Gift a user a random gift?


I’m looking to make a command that when you type !gift user it will give said user a random gift. Does anyone know how to make something like this?


@geekygoat You can use $(eval) to store a list of items in an array and output a random item from that array. Copy and paste this into chat:

!addcom -cd=5 !gift $(user) gives $(touser) $(eval a=[`item 1`,`item 2`,`item 3`,`etc...`];a[Math.floor(Math.random()*a.length)])

Replace item 1, item 2, and item 3 with your various gifts. You can add as many items as you wish. Make sure each item is bounded by backticks (``) and separated by commas as shown above.

Hm… Didn’t work, but thank you! I’ll keep trying to work with it. c:

The command setup I wrote should work. Did you follow the instructions for entering gift options into the array (bounded by backticks `` and separated by commas)?

Yes. I typed it all in like you said but it didn’t work.

Try copying and pasting the command setup as it is into chat without replacing anything. Give it a try to make sure you’ve added it correctly. Then edit the command response to include all the gift options.

It’s also important not to have any backticks inside the items themselves, otherwise the code may break.

It didn’t work. I can get away without this command, but thank you for your help.

@geekygoat I stopped by your channel. It appears that Nightbot isn’t joined to your channel and isn’t a mod.

Go here and login to your Twitch account. Click “Join Channel”.
Mod Nightbot by typing this into chat: /mod Nightbot

I know that I don’t use Nightbot. A lot of them will still transfer over to the bot that I do use (I use a lot of nightbot commands for my bot even though it isn’t nightbot). I have found someone with the command who will send it to me later.

Are you by chance using Streamlabs Chatbot (formerly Ankhbot)? The command variables are similar but still quite different. You’re probably looking for this:

Make a txt file with one gift option written on each line. Name the file whatever you want then copy the file location.

Then copy and paste this into chat:

!command add !gift +a $username gives $targetname $readrandline(YourFileLocationHere)

Replace YourFileLocationHere with your file location.

For future reference, feel free to ask Streamlabs Chatbot-related questions on their Discord support server:

If you do not use nightbot then you should not be asking for support on the nightbot forums

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