Create a catch-all command to respond to any message?

I am working with AI, and so will actually likely only need a single command for the foreseeable future but I wanted to leave room for growth. What I actually want now is the ability to @mention the bot with a query: @bot translate x to y. The Command class from what I gather will only trigger based on the name and the aliases? Makes sense, just wondering if there is a way to maybe fall-back if the bot is pinged and does not match a command, could there be a "default" command? edit: Currently looking more at listeners as a possible solution.
8 Replies
Ben
Ben8mo ago
The UnknownMessageCommandName event is "Emitted when a message starts with a valid prefix but does not include a command name." TSDoc in code Code that emits UnknownMessageCommandName I also just learned that all the events are listed in the docs here so you don't need to go digging through the source code to find them like I did. There's also UnknownMessageCommand which is "Emitted when the name of a sent message command does not match any loaded commands." and actually might be what you want
Favna
Favna8mo ago
mention prefixes are enabled by default when enabling message commands so if you just add a command called translate and parse args accordingly this will just work ootb
TechSquidTV
TechSquidTVOP8mo ago
I am not trying to make a command called translate. I want any generic text passed to the mention to be treated exactly the same. I am using AI to handle the logic
Favna
Favna8mo ago
then you probably want to follow what Ben said
TechSquidTV
TechSquidTVOP8mo ago
@Ben Thanks for sharing this. Would you be making the @bot the prefix in that case? I may actually dumb down to just Discord.JS but I have a feeling that will bite me later
Favna
Favna8mo ago
Whatever you do, keep in mind that there is a very very tiny chance that you'll get message content privileged intent for this purpose because discord (rightfully so) wants you to implement slash commands. And you only get message content intent if you really need it and this likely won't be reason enough So your bot can likely never grow beyond 100 servers if you walk this path
TechSquidTV
TechSquidTVOP8mo ago
That's a bit of a bummer but luckily this is meant to be run on a single server. Appreciate that info though
Oreo ™
Oreo ™8mo ago
i just wanna give my two cents here. i think u should just listen for messageCreate and then filter out messages that dont start with the bot mention and then emit a custom event called something like idk "prompt" client.emit("prompt", message) or u could remove the mention from the message content and do client.emit("prompt", message, prompt) which you can then listen for and then respond accordingly
Want results from more Discord servers?
Add your server