-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
51 lines (39 loc) · 1.6 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
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
const CommandDeployer = require('./deploy-commands')
const { token, bot } = require('./config');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
//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}`);
// 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);
}
// When the client is ready, run this code (only once)
client.once('ready', async () => {
if (process.env.LOAD_SLASH_COMMANDS.toLowerCase() === 'true') {
CommandDeployer.setClient(client)
await CommandDeployer.loadCommands()
await CommandDeployer.setPermissions()
}
await client.user.setActivity(bot.activity_message , { type:bot.activity });
await client.user.setStatus(bot.activity_status);
console.log('Ready!');
});
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);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
// Login to Discord with your client's token
client.login(token);