blob: fdcc8c2a5e15ef220fd5b2f71a8b569eb4b75ad5 (
plain) (
blame)
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
|
import { Client, Events, Collection, InteractionType, GatewayIntentBits } from 'discord.js'
import config from './config.json' assert { type: 'json' }
import { readdirSync } from "node:fs";
const bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates] });
bot.commands = new Collection();
const commandFiles = readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const { default: command } = await import(`./commands/${file}`);
bot.commands.set(command.data.name, command);
}
bot.once(Events.ClientReady, async() => {
console.log('Bot is ready');
})
bot.on(Events.InteractionCreate, async interaction => {
if (interaction.type === !InteractionType.ApplicationCommand) return;
if (!interaction.isChatInputCommand()) return;
const command = bot.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, bot);
} catch (e) {
console.error(e);
await interaction.reply({ content: `There was an error while executing this command...\n\nDetails:\`\`\`${e}\`\`\``, ephemeral: true });
}
});
bot.login(config.token);
|