Your First "Hello World" Script



Hi to all, I am also someone new to PhantomBot or even botting in Twitch as a whole so I can understand the frustration of people trying to find out what to do your first custom script. (Not those you customize in the commands panel but those you literally script yourself.)

I believe, nonetheless, this still does requires the following:

  • Javascript (For obvious reasons :yum: )
  • Notepad++ (Recommended for non-IDE users)

This also doesn’t teach you the entirety that you would need for whatever you plan to do. It’s literally the basics or something to start you off like a template.

  1. Create a script file as follows (PhantomBot/scripts/commands) (I haven’t try it out but anywhere in the scripts folder should be fine.)

  2. Copy the content in the following link to your new command.js file: (My example, helloWorld.js)

  3. Take a look at the different points or change the following to fit your script:

  • (a) Ensure that you change that to the command you wish to use in the chat (e.g. !command)
  • (b)As explained in the comments, the ‘if else’ is unnecessary unless you want to use for arguments to check for options and stuff
  • ©Change the ‘./commands/helloWorld.js’ to the directory of your command. (E.g. your script might be a game so you placed it in the game, then that would be ‘./games/yourGame.js’)
  • (Still c)The final ‘helloworld’ ensure it’s the same as the one in (a)
  1. Make sure you save your script and run the bot.

  2. Check that there is no error in the bot console.(Script error can be seen here as well: ./logs/core-error/DD-MM-YYYY.txt)

  3. Go to your channel and try your new script :slight_smile:
    Doesn’t look the best but it WORKS! :smiley:

Hope this tutorial works for you. (Using PB 2.3.8)

Do note that there are other things to be concerned of like how to get the script to be seen in the disable modules page.
I can do those up but at least for now, this should give you an easier time starting out on something.

I am still learning too so I hope I can get your feedback on this.

Custom Variable in runcode Command
Rename !adventure command
Custom commands with spaces

Nice to see a tutorial for the beginners!

Some things not mentioned:

Generally all scripts (minus your lang files) are going to start out looking like this:

(function() {

There’s different functions you can add into a script to make it communicate with the bot in certain ways.

For instance:

$.bind('command', function(event) {

This creates a function in your script to listen for a command event in the bot. Then you can populate it with variables and various other stuff (as seen in the tutorial above).

$.bind('initReady', function() {

This one creates a function that will be ran once the bot has loaded the script (and it is ‘ready’). You typically register the chat commands here, as it’s called on the bot load, and you only need to register a command once.

There are more functions you can bind, such as $.bind('ircChannelMessage', function(event) { for listening to chat messages.


It’s thanks to your counter script that I got some hint on what is the basics.


The content of this url is not a javascript! Or did I miss something?


You copy the whole text into a file with the .js extension.

It’s not a link to download from.


So, open the page over the link, right click, view source, then copy everything, and then paste to the new .js file?


View source?

That’s not necessary. Just copy that text from the link into a .js file.


This one “We are trying to connect to the server.”? :slight_smile:
Is maybe here something broken?


I copy paste to my current setup. it’s fine, with no changes to the code at all…

Does the same error happen when you remove the script?
also when does that error show up?


The webpage will display “We are trying to connect to the server” as it loads. It should go away shortly.

However, if it doesn’t, here’s an alternate link from hastebin:

Press CTRL+S and it will prompt you to save it as a text document. Click the “Text Document” drop down and change it to “All files”, now rename the file to “helloWorld.js” and save. Congrats! you just made a javascript file :smiley:


Just a note, you should edit your guide to use a folder named custom or something similar like we suggest. It’s bad practice to pollute the area for base scripts with custom scripts. Not to mention making it harder for the end user to track what scripts are modified and need to be ported over on update.

Small edit: I would also recommend removing the “you need JS” portion as it can be a bit deceptive. That implies/appears to imply that you will need to download or acquire something, when in reality as long as you have PhantomBot you will be able to utilize the version of JavaScript Rhino provides.

Other than that it’s nice to see people helping out others with what they have picked up along the way. I may try to compose a sort of list of useful functions at some point and edit the main documentation, if anyone else wants to reply here with any they have/can think of feel free.


Thanx for the fix! Now both URL is working :slight_smile: I can see the javascript code.