-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (36 loc) · 1.45 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
const fs = require('fs');
const { Client, Collection, GatewayIntentBits, Partials } = require('discord.js');
const { Player } = require('discord-player');
// Check for token in env vars
if("TOKEN" in process.env) {
console.log('Found token in environmental variables, loading');
var token = process.env.TOKEN;
} else {
var { token } = require('./config.json');
}
// Create instances
global.client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates], presence: { activities: [{ name: 'Music', type: 'LISTENING' }], status: 'dnd' }});
client.player = new Player(client);
// Read Events
require('./events/player/player.js')
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));
}
}
// Read Commands
client.commands = new Collection();
fs.readdirSync('./commands/').forEach(dirs => {
const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js'));
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
client.commands.set(command.data.name, command);
delete require.cache[require.resolve(`./commands/${dirs}/${file}`)];
};
})
// Login to Discord with client's token
client.login(token);