Get command used with a message object

Is there any way to know which command was used only by having a message object?
9 Replies
Favna
Favna•5mo ago
Parse it out of message.content. It'll be a bit tough because with only a message object you don't know what prefix was used but it's possible. For example you could to write an algorithm that tries to match each of your command names within the first three-or-so words (space delimited) then use the filtered list and use a distance algorithm to match which command was most likely matched (make sure that if you get s 100% match you don't do the distance algorithm). Examples of distances algorithms can be found here: https://en.m.wikipedia.org/wiki/Edit_distance
-Carlos👑
-Carlos👑•5mo ago
I can access the .content from it
Favna
Favna•5mo ago
Yes that's what I said pepeHmm you meant can't In which case there is no way
kyra
kyra•5mo ago
Is this for any message? Or for new ones only?
-Carlos👑
-Carlos👑•5mo ago
new ones, i'm trying to make it so users don't get punished by automod for changing their custom role icon with a link
message.content.startsWith(container.config.client.options.defaultPrefix) &&
message.content.toLowerCase().includes('role icon');
message.content.startsWith(container.config.client.options.defaultPrefix) &&
message.content.toLowerCase().includes('role icon');
This is what I was using but for example if the user uses the bot's mention then it won't work
Ben
Ben•5mo ago
Have you considered making the command a chat interaction command instead of a message command? There's no need to filter out messages in your listener if users don't send messages with a command.
-Carlos👑
-Carlos👑•5mo ago
I wouldn't rewrite all my bot just for one command and not sure what you mean by "users don't send messages with a command."
Ben
Ben•5mo ago
Fair enough I guess. I meant that if the command were a chat interaction command, users would send an interaction instead of a message to trigger the command. Interactions don't trigger message create listeners which I assumed your auto mod use.
-Carlos👑
-Carlos👑•5mo ago
oh I understand now