Slash Commands Test

This commit is contained in:
Dragon Fire
2024-04-07 20:10:26 -04:00
parent 204c056ea1
commit 76fd56b03a
7 changed files with 107 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
module.exports = class SlashCommand {
constructor(client, options) {
Object.defineProperty(this, 'client', { value: client });
this.name = options.name.toLowerCase();
this.description = options.description;
this.credit = options.credit || [];
this.credit.push({
name: 'Dragon Fire',
url: 'https://github.com/dragonfire535',
reason: 'Code'
});
}
};
+45
View File
@@ -0,0 +1,45 @@
const { SlashCommandBuilder, Routes } = require('discord.js');
const { Collection } = require('@discordjs/collection');
const fs = require('fs');
const path = require('path');
const { TEST_GUILD_ID } = process.env;
module.exports = class SlashRegistry {
constructor(client) {
Object.defineProperty(this, 'client', { value: client });
this.commands = new Collection();
}
registerCommand(command) {
const slashCmd = new SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description);
this.commands.set(command.name, { command, data: slashCmd });
return this;
}
registerCommandsIn(dir) {
const commands = fs.readdirSync(dir);
for (const command of commands) {
if (!command.endsWith('.js')) continue;
const Required = require(path.join(dir, command));
this.registerCommand(new Required(this.client));
}
return this;
}
uploadTestCommands() {
return this.client.rest.put(
Routes.applicationGuildCommands(this.client.id, TEST_GUILD_ID),
{ body: this.commands.map(cmd => cmd.data.toJSON()) }
);
}
uploadGlobalCommands() {
return this.client.rest.put(
Routes.applicationCommands(this.client.id),
{ body: commands }
);
}
};