forked from NGIT-Open-Source/Neil.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1.46 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
// Following the best practices are necessary for proper maintainance of code
// For info refer:
// 1.https://discordjs.guide/creating-your-bot/command-handling.html
// 2.https://discordjs.guide/creating-your-bot/event-handling.html
require('dotenv').config();
const fs = require('fs');
const { Client } = require('discord.js');
const startServer = require('./server');
const { setSlashCmds } = require('./events/slashCommands');
const { DiscordTogether } = require('discord-together');
// Intents are like permissions for the bot. Here's a list of intents available
// https://discord.com/developers/docs/topics/gateway#gateway-intents
const gateway_intents = ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES'];
// Creates a new client instance
const client = new Client({ intents: gateway_intents });
// discord-together init
client.discordTogether = new DiscordTogether(client);
// Loops through events folder and an array of events .js files are stored in eventFiles
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
// Sets Slash Commands
setSlashCmds(client);
// Aynchronously listens to events
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));
}
}
// START EXPRESS SERVER
startServer();
// Login to Discord with your bot token
client.login(process.env.token);