-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
44 lines (39 loc) · 1.5 KB
/
bot.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
// init Discord
const { Client, Collection, GatewayIntentBits, Partials } = require('discord.js');
// init env variables
require('dotenv').config();
// init filesystem
const fs = require('node:fs');
// init config
global.config = require('./config.json');
const BotToken = process.env.CLIENT_TOKEN;
// init Discord client
global.client = new Client({
allowedMentions: { parse: ['users', 'roles'], repliedUser: true },
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
// commands
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
// events
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, (...args) => event.execute(...args));
}
else {
client.on(event.name, (...args) => event.execute(...args));
}
}
// logging errors & warns
client.on('error', (e) => console.error(e));
client.on('warn', (e) => console.warn(e));
process.on('uncaughtException', (e) => console.warn(e));
// Login the bot
client.login(BotToken);