From 63682deb929a1a201f4c344f0eaea5ae449b05ac Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 21 Dec 2022 17:54:16 -0500 Subject: Inital commit (aka start of this garbage dump --- index.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 index.js (limited to 'index.js') diff --git a/index.js b/index.js new file mode 100644 index 0000000..fdcc8c2 --- /dev/null +++ b/index.js @@ -0,0 +1,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); -- cgit v1.2.3