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
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
I can access the .content from it
Yes that's what I said you meant can't
In which case there is no way
Is this for any message? Or for new ones only?
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
This is what I was using but for example if the user uses the bot's mention then it won't work
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.
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."
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.
oh I understand now