-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (56 loc) · 2.28 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { Client, Collection, Intents } = require('discord.js');
require('dotenv').config();
const fs = require('fs');
const token = process.env.TOKEN;
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.commands = new Collection();
client.selectCommands = new Collection();
const commandDirs = fs.readdirSync('./commands');
const selectCommandDirs = fs.readdirSync('./selectCommands');
for (const dir of commandDirs) {
const commandFiles = fs.readdirSync(`./commands/${dir}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${dir}/${file}`);
client.commands.set(command.data.name, command);
}
}
for (const dir of selectCommandDirs) {
const selectCommandFiles = fs.readdirSync(`./selectCommands/${dir}`).filter(file => file.endsWith('.js'));
for (const file of selectCommandFiles) {
const command = require(`./selectCommands/${dir}/${file}`);
client.selectCommands.set(command.data.name, command);
}
}
fs.readdir('./events/', (err, files) => {
if (err) return console.error;
files.forEach(file => {
if (!file.endsWith('.js')) return undefined;
const event = require(`./events/${file}`);
const evtName = file.split('.')[0];
client.on(evtName, event.bind(null, client));
});
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
client.on('interactionCreate', async interaction => {
if (!interaction.isSelectMenu()) return;
const command = client.selectCommands.get(interaction.customId);
if (!command) return;
try {
await command.data.execute(interaction);
} catch (error) {
console.error(error);
return interaction.reply({ content: 'There was an error while executing this select command!', ephemeral: true });
}
});
client.login(token);
client.on("ready", () => {console.log('Bot démarré')});