39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
const { Client, GatewayIntentBits, Collection } = require('discord.js');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const deployCommands = require('./deploy-commands');
|
|
|
|
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers] });
|
|
|
|
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 });
|
|
}
|
|
});
|
|
|
|
client.on('guildCreate', guild => {
|
|
deployCommands(guild.id);
|
|
});
|
|
|
|
const login = () => {
|
|
client.login(process.env.DISCORD_BOT_TOKEN);
|
|
}
|
|
|
|
module.exports = { login, client }; |