-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (30 loc) · 1.16 KB
/
index.js
File metadata and controls
40 lines (30 loc) · 1.16 KB
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
const { Client, Events, GatewayIntentBits, Collection } = require("discord.js");
const commands = require("./commands/index.js");
require('dotenv').config();
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
for (const command of commands) {
client.commands.set(command.data.name, command);
}
client.on(Events.InteractionCreate, async (interaction) => {
console.log(`${interaction.user.username} triggered the ${interaction.commandName} command on ${new Date().toLocaleString()}.`);
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.warn(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(`${error.message}:\n`, error);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
});
client.once(Events.ClientReady, (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.login(process.env["DISCORD_TOKEN"]);