-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.ts
69 lines (57 loc) · 2.56 KB
/
bot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Require the necessary discord.js classes
import { Client, Collection, Events, GatewayIntentBits, EmbedBuilder, TextChannel } from 'discord.js';
import { ColorConst, DevTestChoice, EnvConst } from './scripts/constants/constants';
import CommandRegist from './scripts/commandRegist';
import EventHandlersInit from './scripts/eventHandler';
import { generateDailyMissions } from './scripts/constants/events';
//Expend a "Commannds" variable
//From https://stackoverflow.com/questions/62860164/stuck-with-adding-variable-to-discord-client-object-typescript
declare module "discord.js" {
export interface Client {
commands: Collection<unknown, any>
}
}
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
//Regist Commands
client.commands = new Collection();
CommandRegist(client);
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
const channelNoti = client.channels.cache.get(process.env.AnnouncementChannel!) as TextChannel;
var embed = new EmbedBuilder()
.setColor(ColorConst.EMBED_ANNOUN_COLOR)
.setTitle("重啟成功通知")
.setDescription("我回來了!另外,所有指令將會在現在重新被執行。當前是在" + EnvConst.NODE_ENV);
if (EnvConst.NODE_ENV !== DevTestChoice.DEVELOPMENT || (!DevTestChoice.isDisableOnlineEmbed && EnvConst.NODE_ENV === DevTestChoice.DEVELOPMENT)) {
channelNoti.send({ embeds: [embed] });
}
//EventHandlersInit(readyClient);
generateDailyMissions(readyClient,1)
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on(Events.MessageCreate, message => {
console.log(message.content)
message.channel.send("DLL")
});
// Log in to Discord with your client's token
client.login(process.env.TOKEN_KEY);