You can add a username to a Nightbot command using two main variables:
$(user) to reference the user who typed the command, or $(touser) to mention a different user targeted by the command. Both variables can be used in combination with an @ symbol to tag the user directly in the chat.
How to add the username of the person who uses the command
This is the most common use case for commands like !lurk or !hug. The command's response will automatically insert the name of the person who initiated it.
1. Go to your Nightbot dashboard
- Log in to Nightbot.tv and navigate to the Commands section, then select Custom.
2. Create a new command
- Click the +Add Command button.
- Command: Type the name of your command, such as
!lurk. - Message: In the message box, type your desired response, and use
$(user)where you want the user's name to appear.
Example message for a lurk command:
Thank you for lurking, $(user). Your support is appreciated!
How it works:
- When a user named
StreamerFantypes!lurkin your chat, Nightbot will respond:Thank you for lurking, StreamerFan. Your support is appreciated!.
How to add the username of a targeted user
This is perfect for shoutout commands (!so) or any command where a user mentions another person. The $(touser) variable will grab the first word that follows the command and insert it into the response.
1. Go to your Nightbot dashboard
- Navigate to Commands > Custom.
2. Create a new command
- Click the +Add Command button.
- Command: Type the name of your command, such as
!so. - Message: Type your response, using
@$(touser)to directly tag and mention the other user.
Example message for a shoutout command:
Go check out the amazing @(touser)!Theywerelastplayingopen paren t o u s e r close paren exclamation mark cap T h e y w e r e l a s t p l a y i n g
(𝑡𝑜𝑢𝑠𝑒𝑟)!𝑇ℎ𝑒𝑦𝑤𝑒𝑟𝑒𝑙𝑎𝑠𝑡𝑝𝑙𝑎𝑦𝑖𝑛𝑔
(twitch $(touser) "game").
How it works:
- When
StreamerFantypes!so @AmazingCreator, Nightbot will respond:Go check out the amazing @AmazingCreator! They were last playing (their last streamed game).. - If the command is used without a target (e.g., just
!so),$(touser)defaults to the name of the user who typed the command (StreamerFan), resulting inGo check out the amazing @StreamerFan!.
How to combine both variables in one command
For more complex interactions, you can use both variables in a single command. This is useful for "interactions" or "fun" commands.
1. Go to your Nightbot dashboard
- Navigate to Commands > Custom.
2. Create a new command
- Click the +Add Command button.
- Command: Type the command name, for example,
!hug. - Message: Use
$(user)for the sender and$(touser)for the recipient.
Example message for a hug command:
(user)givesopen paren u s e r close paren g i v e s
(𝑢𝑠𝑒𝑟)𝑔𝑖𝑣𝑒𝑠
(touser) a big hug!
How it works:
- If
StreamerFantypes!hug @AmazingCreator, Nightbot will respond:StreamerFan gives AmazingCreator a big hug!. - If
StreamerFantypes only!hug, Nightbot will respond:StreamerFan gives StreamerFan a big hug!.
Step-by-step setup guide on Nightbot
For a practical demonstration, here's how to create a custom !lurk command.
- Access Nightbot: Log in to your account at nightbot.tv.
- Navigate to commands: In the left-side navigation menu, click Commands, then Custom.
- Add a new command: Click the +Add Command button in the top-right corner.
- Fill in the details:
- Command:
!lurk - Message:
$(user) has entered the shadows. Thanks for your support! - Userlevel: Set to
Everyoneso anyone can use it. - Cooldown:
5seconds is a good standard to prevent spam. - Alias: You can leave this blank.
- Command:
- Submit: Click Submit to save your new command.
- Test the command: Go to your Twitch or YouTube chat and type
!lurkto see Nightbot's response with your username included.
Advanced username functionality with Nightbot
While $(user) and $(touser) cover most common needs, Nightbot offers even more complex features for advanced users, often by combining variables with conditional logic.
Personalized responses with Pastebin
For situations where you want Nightbot to respond differently to specific users, you can use a Pastebin to manage the response text.
1. Create your Pastebin
- Go to pastebin.com and create a new paste.
- Use a JavaScript
switchstatement to define different responses for different usernames. - Example Pastebin content:```
switch ('$(user)'.toLowerCase()) {
case 'streamerfan':
'Welcome back, StreamerFan! So glad to have you here.';
break;
case 'amazingcreator':
'Everyone give a warm welcome to AmazingCreator!';
break;
default:
'Hello, $(user)! Enjoy the stream.';
break;
}
- Save the paste and get the raw URL.
2. Create the Nightbot command
- Command:
!welcome - Message:
$(eval $(urlfetch json YOUR_PASTEBIN_RAW_URL)) - Replace
YOUR_PASTEBIN_RAW_URLwith the raw URL from your Pastebin. - Userlevel:
Everyone
How it works:
- When a user types
!welcome, Nightbot fetches the content from your Pastebin, evaluates the JavaScript, and sends the corresponding message. This allows for highly customized, user-specific command responses.