How to create a !fight command?

I’ve seen another bot have a command called !fight which the user types !fight and it says something along the lines of e.g. ‘User used a gun to fight user who had a knife and lost’.

Is there a way to create a command similar to this which would say something like:

!fight

User fought user and won by KO

Or

User fought user and lost by submission

Etc.

This command should work, its a combination of 2 urlfetch variables, the first one picks a random viewer, the seconds one gets the random response:
!commands add !fight $(user) fought $(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel)) and $(urlfetch https://api.rtainc.co/twitch/random?format=[0]&choices=won by KO,lost by submission).

You can add more random responses to the second urlfetch comma-separated, for example:
&choices=won by KO,lost by submission,response a,response b,reponse c,response d

1 Like

@xgerhard Thanks man. But a problem I have is that there is a character limit, it won’t let me add the amount of random choices I want. Is there anyway I can apply all of my random choices but not in the api link so I can bypass the character limit?

Hmm, not the most ideal situation, but you could create a long link with all the choices and make a bit.ly link from it, then put that link in the urlfetch.

@xgerhard That worked. Thanks! But also, instead of a random viewer, I would like it to be a viewer that I type in, if I didn’t type in a correct user, it would reply with a response saying :

!fight

Error: Please type in a valid user

Is this possible?

You can use the $(touser) variable, when you type !fight testuser, it will display the testuser, but if you just type !fight, it will display your own name.

I tried that but it seems to work exactly like the $(query) variable. I would like it to give an error if you don’t type the correct name or any name at all. @xgerhard

There is no built in function like that, so you would need to create a custom API for something specific like that.

https://docs.nightbot.tv/commands/variables/urlfetch

@xgerhard ah okay, thanks for your help

@xgerhard sorry if it’s too much to ask man but would you know how to make an api like that?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.