-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
53 lines (47 loc) · 1.62 KB
/
main.js
File metadata and controls
53 lines (47 loc) · 1.62 KB
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
const Discord = require("discord.js");
const intents = new Discord.Intents();
const bot = new Discord.Client({intents: 8});
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { discordToken, clientId } = require('./src/config.json');
const fs = require('fs');
bot.on('ready', () => {
console.log('The bot has successfully started.');
bot.user.setPresence({
activities: [{
name:"servers",
type: "WATCHING"
}],
status: "dnd"
})
});
const commands = [];
bot.slashcommands = new Discord.Collection();
const commandFiles = fs.readdirSync('./src/commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./src/commands/${file}`);
commands.push(command.data.toJSON());
bot.slashcommands.set(command.data.name, command)
}
const rest = new REST({ version: '9' }).setToken(discordToken);
(async () => {
try {
console.log('Started to reload slash commands.');
await rest.put(Routes.applicationCommands(clientId), { body: commands });
console.log('Slash commands have been successfully reloaded.');
} catch (error) {
console.error(error);
}
})();
bot.on('interactionCreate', async(interaction) => {
// console.log(interaction.guild.roles.cache.filter(role => {console.log(interaction.member.roles.includes('992458634317545484'))}))
if(!interaction.isCommand()) return;
const slashcmds = bot.slashcommands.get(interaction.commandName);
if(!slashcmds) return;
try {
await slashcmds.run(bot, interaction);
} catch(e) {
console.error(e);
}
});
bot.login(discordToken);