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
- 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!
now, using this in another file results in the error:
the error of course stemming from the .setName()
so im wondering, how can I create a group i can use across multiple files?
so you want to split your subcommands in multiple files?
Yeah
I cannot stand having cluttered files, so imagine like 8 commands in one file
yuck
apparently i cant spell
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
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
was just typign something similar
okay bro thank you
I was hoping to avoid that but oh well Ill suffer 💔
appreciate it
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
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
I cant wait to port to typescript
my life is gonna be so sexy
and I did what we originally said thanks guys