aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2022-12-21 17:54:16 -0500
committerAndrew Lee <alee14498@protonmail.com>2022-12-21 17:54:16 -0500
commit63682deb929a1a201f4c344f0eaea5ae449b05ac (patch)
tree3696db53fd13666c77afdc265ee8191cf1c2568d /index.js
downloadshrimpbot-js-63682deb929a1a201f4c344f0eaea5ae449b05ac.tar.gz
shrimpbot-js-63682deb929a1a201f4c344f0eaea5ae449b05ac.tar.bz2
shrimpbot-js-63682deb929a1a201f4c344f0eaea5ae449b05ac.zip
Inital commit (aka start of this garbage dump
Diffstat (limited to 'index.js')
-rw-r--r--index.js33
1 files changed, 33 insertions, 0 deletions
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);