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 solution
13 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
DiabolusGX
DiabolusGXOP•2y ago
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 suggestion
monbrey
monbrey•2y ago
Why do you have both is the real question
DiabolusGX
DiabolusGXOP•2y ago
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
Yinoguns
Yinoguns•2y ago
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
DiabolusGX
DiabolusGXOP•2y ago
Thanks for suggestions 🙂
mahakadema
mahakadema•2y ago
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)
DiabolusGX
DiabolusGXOP•2y ago
what exactly you mean by ctx? I'm not very familiar with interactions, just getting started
mahakadema
mahakadema•2y ago
i have this in my slash command handler, ctx has all the context you would usually get from interaction.channel interaction.user etc.
mahakadema
mahakadema•2y ago
i have a similar object in my old message handler, but here ctx is populated from the properties on message
mahakadema
mahakadema•2y ago
then i have a lot of really old junky code that populates args using my command syntax declaration
mahakadema
mahakadema•2y ago
and 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)
DiabolusGX
DiabolusGXOP•2y ago
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() 😛
Want results from more Discord servers?
Add your server