Better way to plugin slash commands support with existing msg content commands
Can someone suggest a way to plugin interactions with existing command structure for djs? like it's mentioned on djs guide - command file will have few properties and 1 exec function
I can see 2 ways here:
1. I extract whole business logic in different functions and keep communication fn different for msg content and slash command
2. I can put
if
checks and use proper fn of msg or interaction to reply
Not satisfied with either and looking for better solution13 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
1 more way I can think of -
I send treat
interaction
as message
only and modify all commands such that I'll extract only common info from both (msg & interaction)
but command args & reading from options will still be pain
Please ping if someone has any suggestionWhy do you have both is the real question
I can't migrate all commands at once so keeping both options & migration few commands at a time
Also, I need to take message input & slash commands won't have new line and emojis
Okay but still want to keep conventional prefix commands cuz most of the users are used to it and might miss that bot is migrated to slash commands.. keeping support for both (in organised manner) is what I actually need help with
Best I'd recommend is moving to slash fully, keep the prefix for like a month but update all prefix to say "moving to slash, here's the new command <>" and have a command mention to make their transition easier
Thanks for suggestions 🙂
this is what i did, extract
ctx
and args
containing context and arguments respectively.
Though I have to say, having done it, it's more hassle than it's worth
(It did end up with me having a pretty nice command handler, allowing me to easily add new commands. Still not a good investment of my time, though)what exactly you mean by ctx? I'm not very familiar with interactions, just getting started
i have this in my slash command handler, ctx has all the context you would usually get from
interaction.channel
interaction.user
etc.i have a similar object in my old message handler, but here ctx is populated from the properties on
message
then i have a lot of really old junky code that populates
args
using my command syntax declarationand in the end, both of these give me the same 2 objects, no matter whether i do
/coolstuff user:@mahakadema optionalArg: 14
or
!coolstuff @mahakadema --optionalArg 14
(the ctx in the message handler is missing a couple properties, because i phased out message commands some time ago and didn't update it to the newest version)
(oh, and none of my commands use
interaction.reply
or message.channel.send
, they just return the message to send, and then the respective handler actually calls the correct function to use)Thanks a lot for help, I'm also implementing something similar but having pre-defined structure will help a lot (ctx in your case)
I started with writing wrapper to rely commands (both prefix & interactions)
Will give it a thought and see if such effort is worth it or not
I attached a function to client and I use
client.send()
😛