-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (41 loc) · 1.47 KB
/
index.js
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
import { Client, Events, GatewayIntentBits, Collection } from 'discord.js';
import path from 'path';
import dotenv from 'dotenv';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
dotenv.config();
const { TOKEN } = process.env;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const commandsPath = path.join(__dirname, "commands");
const commandsFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js"));
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
for(const file of commandsFiles){
const filePath = `./commands/${file}`;
const commandModule = await import(filePath);
const command = commandModule.default;
if ("data" in command && "execute" in command){
client.commands.set(command.data.name, command)
} else {
console.log(`This command in ${filePath} is missing either date or execute!`);
}
}
client.on(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) {
return;
}
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.log(error);
await interaction.reply("There was an error executing this command!");
}
});
client.login(TOKEN);