Grouped slash commands

Good evening everyone. I'm just sort of wondering how I can use a group across multiple files. For instance, say I have a /Cogs/Moderation/ structure. Inside of Moderation, I'd like ban.js kick.js, you get the gist. So inside of my ban.js I create a group like so:
9 Replies
d.js toolkit
d.js toolkit•3w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
b00bs
b00bsOP•3w ago
export default {
data: new SlashCommandBuilder()
.setName('mod')
.setDescription('Kick or ban a user from the server')
.addSubcommand(subcommand =>
subcommand
.setName('ban')
.setDescription('Bans the given user from the guild')
.addUserOption(option =>
option
.setName('target')
.setDescription('The user to ban')
)
)
export default {
data: new SlashCommandBuilder()
.setName('mod')
.setDescription('Kick or ban a user from the server')
.addSubcommand(subcommand =>
subcommand
.setName('ban')
.setDescription('Bans the given user from the guild')
.addUserOption(option =>
option
.setName('target')
.setDescription('The user to ban')
)
)
now, using this in another file results in the error:
[0] [@bot] [ERROR]DiscordAPIError[50035]: Invalid Form Body
[0] 3[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique
[0] [@bot] [ERROR]DiscordAPIError[50035]: Invalid Form Body
[0] 3[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique
the error of course stemming from the .setName() so im wondering, how can I create a group i can use across multiple files?
Amgelo
Amgelo•3w ago
so you want to split your subcommands in multiple files?
b00bs
b00bsOP•3w ago
Yeah I cannot stand having cluttered files, so imagine like 8 commands in one file yuck apparently i cant spell
Amgelo
Amgelo•3w ago
you could make your parent an actual command and then split each "execute" function for each subcommand in different files your parent would have something like
execute(interaction) {
switch(subcommand) {
case "one":
executeSubcommandOne(interaction);
// etc
execute(interaction) {
switch(subcommand) {
case "one":
executeSubcommandOne(interaction);
// etc
where "executeSubcommandOne" is on a different file. I'm on phone so it's really hard to do formatting but you can get the gist
b00bs
b00bsOP•3w ago
was just typign something similar okay bro thank you I was hoping to avoid that but oh well Ill suffer 💔 appreciate it
Amgelo
Amgelo•3w ago
I mean you can structure it any way you'd like djs doesn't care about how you do it it's just that that is probably the easiest way to split it another way would be having your subcommands export a subcommand builder, and through your folder structure it can map a folder name to the parent it belongs it's more complex but doable you'd also need to change your handler
vince
vince•3w ago
Going off of Amgelo, I have mine setup inside a switch and then I just import the subcommand function from another file: https://github.com/v11ncent/discord-yakuza/blob/main/src/commands/leaderboard/leaderboard.ts
b00bs
b00bsOP•3w ago
I cant wait to port to typescript my life is gonna be so sexy and I did what we originally said thanks guys

Did you find this page helpful?