2023-12-17 20:21:26 -05:00
|
|
|
//Boring boring initialization stuff
|
|
|
|
const fs = require('node:fs');
|
|
|
|
const path = require('node:path');
|
|
|
|
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
2023-12-17 19:07:36 -05:00
|
|
|
const { token } = require('./config.json');
|
|
|
|
|
|
|
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
|
|
|
2023-12-17 20:21:26 -05:00
|
|
|
//Handle commands
|
|
|
|
client.commands = new Collection();
|
2023-12-17 19:07:36 -05:00
|
|
|
|
2023-12-17 20:21:26 -05:00
|
|
|
//Command Loading
|
|
|
|
const foldersPath = path.join(__dirname, 'commands');
|
|
|
|
const commandFolders = fs.readdirSync(foldersPath);
|
|
|
|
|
|
|
|
for(const folder of commandFolders) {
|
|
|
|
const commandPath = path.join(foldersPath, folder);
|
|
|
|
const commandFiles = fs.readdirSync(commandPath).filter(file => file.endsWith('.js'));
|
|
|
|
for (const file of commandFiles) {
|
|
|
|
const filePath = path.join(commandPath, file);
|
|
|
|
const command = require(filePath);
|
|
|
|
if ('data' in command && 'execute' in command) {
|
|
|
|
client.commands.set(command.data.name, command);
|
|
|
|
} else {
|
|
|
|
console.log(`WARN: Command at ${filePath} is missing 'data' and/or 'execute' properties.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Command Interaction Processing
|
|
|
|
client.on(Events.InteractionCreate, async interaction => {
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
|
|
|
|
const command = interaction.client.commands.get(interaction.commandName);
|
|
|
|
|
|
|
|
if (!command) {
|
|
|
|
console.error(`ERR: Command "${interaction.commandName}" not found`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await command.execute(interaction);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
if (interaction.replied || interaction.deferred) {
|
|
|
|
await interaction.followUp({ content: `ERROR!`, ephermal: true});
|
|
|
|
} else {
|
|
|
|
await interaction.reply({ content: `ERROR!`, ephermal: true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//Log the bot in with the token supplied in config.json
|
2023-12-17 19:07:36 -05:00
|
|
|
client.once(Events.ClientReady, readyClient => {
|
|
|
|
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
client.login(token);
|
2023-12-17 20:21:26 -05:00
|
|
|
|
|
|
|
|