-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
56 lines (45 loc) · 1.7 KB
/
app.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
const fs = require('fs');
require('dotenv').config();
const { Client, Collection, GatewayIntentBits, Partials } = require('discord.js');
// Discord.js client
const client = new Client({
'intents': [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers,
],
'partials': []
});
// Add command collection to client
// https://discordjs.guide/creating-your-bot/command-handling.html#individual-command-files
client.commands = new Collection();
// Read command files
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
// Add button collection to client
client.buttons = new Collection();
// Read button files
const buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'));
for (const file of buttonFiles) {
const button = require(`./buttons/${file}`);
// Set a new item in the Collection
// With the key as the button name and the value as the exported module
client.buttons.set(button.name, button);
}
// Read event files
// https://discordjs.guide/creating-your-bot/event-handling.html#individual-event-files
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, async (...args) => event.execute(...args));
} else {
client.on(event.name, async (...args) => event.execute(...args));
}
}
client.login(process.env.BOT_TOKEN);