forked from YTG2G3/imposter-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (37 loc) · 1.23 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
// Load .env
require('dotenv').config();
// Load firebase
const { servers } = require('./firebase');
// Create new discord bot client
const fs = require('fs');
const { Client, Intents, Collection } = require("discord.js");
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.DIRECT_MESSAGES] });
// Load commands
require('./deploy-command');
bot.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (let file of commandFiles) {
let command = require(`./commands/${file}`);
bot.commands.set(command.data.name, command);
}
// Bot ready
bot.once('ready', () => {
console.log('Bot is ready!');
});
// Bot joins
bot.on('guildCreate', guild => {
});
// Bot received command
bot.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.user.bot) return;
const cmd = bot.commands.get(interaction.commandName);
if (!cmd) return;
try {
await cmd.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
bot.login(process.env.DISCORD_TOKEN);