Files
valorantDiscordBot/index.js
2022-08-26 18:19:28 +00:00

57 lines
1.4 KiB
JavaScript

'use strict';
const path = require('path');
const { Client, GatewayIntentBits } = require('discord.js');
const config = require(path.join(__dirname, 'config', 'config.json'));
const getCommands = require(path.join(__dirname, 'lib', 'getCommands.js'));
const registerCommands = require(path.join(__dirname, 'registerCommands.js'));
const unregisterCommands = require(path.join(__dirname, 'unregisterCommands.js'));
const client = new Client({ intents: [ GatewayIntentBits.Guilds ] });
client.commands = getCommands();
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand())
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.once('ready', () => {
console.log('\nLogged in!\n');
});
async function main() {
console.log('Discovering commands...');
console.log('- Commands: ' +
client.commands.map(({ data }) => data.name).join(', ')
);
if (config.reregisterOnStartup) {
console.log('- Unregistering commands');
await unregisterCommands();
console.log('- Registering new commands');
await registerCommands();
}
client.login(config.clientToken);
}
main().catch(console.error);