How to have a different message be sent out if the command tags anyone or not

Asked Jul 13, 2022·2 replies·Last activity 4 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Sorry if the phrasing is weird, trying to figure out how to properly phrase what I want in one sentence.

What I am asking for is help setting up a command so one of two things can happen, Either the person just uses the command and the message is directed at them, or they put someone elses name at the end and the message is directed to the other person. example of what I'm trying to say is

User1 uses command !hug-> nightbot "gives" the User1 a hug,
User1 uses command !hug User2-> Nightbot says "User 1 gave User2 a hug".

I am pretty sure it would use the eval varible as one can use $eval a=[example text ,examle text 2,];a[Math.floor(Math.random()*a.length)])! to achieve the same effect but at the cost of it being random on which one it selects. though I don't know any java script and my coding knowledge in general is next to none. So if what I am asking for is possible please help me out, and thank you in advance.

2 replies

Hey @Hasty Chipmunk!

We have a couple topics covering similar needs, please use the search bar before opening a new topic.

Here's how to set up such command:

$(eval '$(user)'.toLowerCase() === '$(touser)'.toLowerCase() ? '/me *hugs $(user)*' : '/me *$(user) hugs $(touser)*')

Because $(user) is equal to $(touser) when the user doesn't tag anyone, we can use that to know if they tagged someone or not.

Thanks, I tried searching for other topic, though admitly I didn't know where to go looking so I found nothing. Again thanks, while I was just using the hug as an example of what I looking, I still was able to use the setup in other commands.