Program Commit
This commit is contained in:
34
discord-bot/index.js
Normal file
34
discord-bot/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const { Client, GatewayIntentBits, Collection } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
client.commands = new Collection();
|
||||
|
||||
const commandHandler = require('./handlers/command-handler');
|
||||
const eventHandler = require('./handlers/event-handler');
|
||||
|
||||
commandHandler(client);
|
||||
eventHandler(client);
|
||||
|
||||
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 });
|
||||
}
|
||||
});
|
||||
|
||||
const login = () => {
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
||||
}
|
||||
|
||||
module.exports = { login, client };
|
||||
Reference in New Issue
Block a user