Version 0.1.0 - Mise en place de Discord.js

This commit is contained in:
2025-02-23 13:54:07 +01:00
parent cb206ffa22
commit b054c8a316
19 changed files with 2465 additions and 2 deletions

View File

@@ -0,0 +1,73 @@
const { SlashCommandBuilder} = require("discord.js");
class Command {
name;
description;
callback;
data;
constructor(name, description, callback, options) {
this.name = name
this.description = description
this.callback = callback
this.options = options
const SlashCommand = new SlashCommandBuilder()
.setName(name)
.setDescription(description)
// Options is an array with the following structure: [{name: "name", description: "description", type: "type", required: true/false, choices: [{name: "name", value: "value"}]}]
if (options) {
options.forEach(SelOption => {
if(SelOption.type === "STRING") {
SlashCommand.addStringOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "INTEGER") {
SlashCommand.addIntegerOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "BOOLEAN") {
SlashCommand.addBooleanOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "USER") {
SlashCommand.addUserOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "CHANNEL") {
SlashCommand.addChannelOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "ROLE") {
SlashCommand.addRoleOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "NUMBER") {
SlashCommand.addNumberOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "SUB_COMMAND") {
SlashCommand.addSubcommand(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "SUB_COMMAND_GROUP") {
SlashCommand.addSubcommandGroup(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "MENTIONABLE") {
SlashCommand.addMentionableOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required))
}
if(SelOption.type === "CHOICES") {
let choices = []
SelOption.choices.forEach(SelChoice => {
choices.push({name: SelChoice.name, value: SelChoice.value})
})
SlashCommand.addStringOption(option => option.setName(SelOption.name).setDescription(SelOption.description).setRequired(SelOption.required).addChoices(choices))
}
})
}
this.data = {data: SlashCommand, async execute(client, interaction) {callback(client, interaction)}}
}
getData() {
return this.data
}
getName() {
return this.name
}
}
module.exports = {Command}