-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
57 lines (51 loc) · 1.47 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
52
53
54
55
56
57
const { Client, Collection, Intents } = require('discord.js');
const fs = require('fs');
const commands = [];
require('dotenv').config();
module.exports = client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
const { REST } = require('@discordjs/rest');
const { Routes } = require("discord-api-types/v9");
client.login(process.env.DISCORD_TOKEN);
client.on('ready', () => {
console.log(`Logged in`);
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);
(async () => {
await client.guilds.cache.get();
console.log("SIZE" + client.guilds.cache.size);
})();
(async () => {
try {
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands },
);
console.log("Commands registered");
} catch (err) {
console.log(err);
}
})();
})
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 (err) {
console.error(err);
await interaction.reply({
content: "An error has occured!",
ephemeral: true
});
}
})