Command help


Hi guys,

I’m a mod for a popular Twitch streamer who has recently switched to Phantombot. I’ve got the general grasp on how the bot functions but could use a little assistance with translating some commands from Nightbot to Phantobot.

I’ve setup the following commands in Phantombot;

!setwins Wins set to (1)! (writefile wins.txt, false, (1)) (adminonlyedit)
!wins STREAMER has (readfile wins.txt) wins today!

Mods can use !setwins X to increase the counter that is read to !wins. It works, but it’s basic. Plus it needs to be manually reset at the start of each day. I’d like to setup something similar to the following though (Nightbot commands);

$(eval allWins = $(urlfetch json","); now =; total = 0; thisMonth = 0; for (i = 0; i < allWins.length; i++){match = allWins[i].match(/^(\d+)|(-?\d+)$/); if (match !== null){timestamp = parseInt(match[1]); wins = parseInt(match[2]); total += wins; if (now - timestamp < 31 * 86400000){thisMonth += wins}}} GAME wins: This month: ${thisMonth}, Total wins: ${total})

!winsadd (alias to !winsadder, userlevel moderator)
$(eval wins = $(query) ? parseInt($(query)) : 1; if (isNaN(wins)){"$INVALIDQUERY$"} else {"?token=SECONDTOKEN&data=" + encodeURIComponent(${}|${wins},)})

!winsadder (userlevel moderator)
$(eval response = $(urlfetch json$(query)); if (response.startsWith("Successfully added entry ")){“The number of wins was updated”} else if ($(query) === “$INVALIDQUERY$”){“Enter a number after !winsadd”} else {“Use !winsadd”})

!winsset (alias to !winssetter, userlevel moderator)
$(eval m=$(query).match(/^(\d+) (\d+)$/);if(m===null){"$INVALIDQUERY$"}else{tM=parseInt(m[1]);t=parseInt(m[2]);if(tM>t){"$INVALIDQUERY$"}else{if(tM>0||t-tM>0){aQ="";if(tM>0){aQ+=${}|${tM},}if(t-tM>0){aQ+=0|${t-tM},}"?token=SECONDTOKEN&data="+encodeURIComponent(aQ)}else{"?token=SECONDTOKEN&$RESET$"}}})

!winssetter (userlevel moderator)
$(eval cR=$(urlfetch json$(query)&clear=1);aR=$(urlfetch json$(query));if(aR==“Successfully added entry #1”){if(cR==“All entries have been deleted”){“The win counter was set”}else{Error resetting (${cR})}}else if($(query)=="$INVALIDQUERY$"){“Enter the number of wins this month and the total number of wins after !winsset”}else if($(query).includes("$RESET$")){“The win counter was reset”}else{“Use !winsset”})

!wins: Viewers type this to see this month’s (31 days) win count and the total win count.
!winsadd: Mods type this, followed by a number, to add to this month’s win count and the total win count. If no number is specified, then 1 is used. Each win is timestamped, so 31 days after being added, a win will no longer be counted in this month’s wins.
!winsadder: Utility command for !winsadd that shouldn’t be manually used.
!winsset: Mods type this, followed by this month’s win count, followed by a space, followed by the total win count, to set them. This completely erases what was added with !winsadd.
!winssetter: Utility command for !winsset that shouldn’t be manually used.

Second query.

The base command !multi does not work. Presumably the original installer did not include the module. Not sure why. Anyway to get around it we currently manually do the following;


and then !aliascom !multi !squad

I’d like to setup 2 commands !setsquad and then !squad. !setsquad I’d like to be able to use plain text space delimited names that the command would convert into a URL using a base URL and return under !squad (the same way !multi functions already).

would return on !squad

Thank you for taking the time to read this and hopefully someone can help out.


The first query, I usually code JavaScript modules for everything, but I know we allow JavaScript to be embedded in custom commands. I would need to check more into that though.

Regarding the second item, I do not know what version you are running, I am running the latest here; no GUI first:

module status ./commands/dualstreamCommand.js
[04-12-2018 @ 12:29:31.193 MDT] [CHAT] @IllusionaryBot, Module dualstreamCommand is currently enabled!
multi set bob frank tom
[04-12-2018 @ 12:29:58.712 MDT] [CHAT] Multi link set! -
[04-12-2018 @ 12:30:45.123 MDT] [CHAT]

GUI (current stock panel):

So, I am not entirely sure why you wouldn’t have multi as it ships with the bot. Are you sure the module was enabled?


Hi IllusionaryOne,

It does seem as though, for whatever reason, the person who originally installed the bot did not enable certain modules. We’ve been unsuccessful in getting them enabled since so we’ve tried to work around it.

Is it possible to enable a module from the console, or re-insert the missing module if the files are not there?


In Control Panel:
Go to the Dashboard –> Twitch Modules and enable ./commands/dualstreamCommand.js


In Chat:
Type (without guotes) “!module enable ./commands/dualstreamCommand.js”


In Console:
Type (without guotes and exclamation mark) “module enable ./commands/dualstreamCommand.js”


By default, most modules are turned off. We have debated internally about this and gone back and forth a lot. Some people prefer being able to pick exactly what they want to turn on rather than turning off a lot of things and other people prefer to just turn off a few things. It is one of those darned if we do and darned if we don’t sort of design decisions.


So yeah. I don’t know what they did when they installed this poor thing but nothing seems to work. I don’t have access to the Dashboard but neither the console nor chat commands elicit a response from the bot.

!multi remains non functional.


If you have access to the bot console, then you actually own that bot, you have direct access to it, and you decide what works in the bot and what doesn’t.

Go to /scripts/commands folder inside your bot folder and check if dualstreamCommand.js whether this file is in its place. If not, copy it from the original PhantomBot zip file.


If the script is found and still not working, make sure that any aliases or custom commands that may have been created that are named multi are removed.

If that fails what I would probably say is we need to see the Console output and any error and stacktrace logs with hopes of that shedding some light on the problem.

If that doesn’t help I would politely ask for a DM of your phantombot.db file (don’t worry, no stream keys or personal information is in there) so I could load it and see if the command works for me or not in my copy of the bot and if the database file needs any adjustments. I of course would need to know what version of PhantomBot you are running (I may have missed it) to make sure that I loaded up with the same version and didn’t apply any automated database patches that occur between releases.


I wanted to report back. We have had success! Manually running the module enable from console got it going. Thank you so much. That’s the largest of my problems sorted out. I can live without fancy win counters.

In saying that though is there a hidden variable/ability to have my !setwins command reset back to 0 at a certain time of day? For reference-

!setwins Wins set to (1)! (writefile wins.txt, false, (1)) (adminonlyedit)


A custom JavaScript module could be written that would wipe it out once a day. I didn’t test this, but it seems right, it will wipe every 24 hours. If you want it to do a specific time of day, that is a little bit trickier, but is possible.

 * resetFileCounters.js
 * Reset counters kept in files once a day.
(function() {
     * @function resetFileCounters
    function resetFileCounters () {
        // This resets the counter the first time the script is ran. If that is not desired then change
        // $.systemTime() / 1000 to ($.systemTime() / 1000) + 86400.
        var lastReset = $.getSetIniDbNumber('auto_counter_reset', 'time_reset_time', $.systemTime() / 1000),
            currentTime = parseInt($.systemTime() / 1000);

        if (currentTime - lastReset < 86400) {

        $.writeToFile('1', './addons/wins.txt', false);
        $.inidb.set('auto_counter_reset', 'time_reset_time', currentTime);

     * @event initReady
    $.bind('initReady', function() {
        // Every five minutes check to see if the counters should be reset.
        var interval = setInterval(function() { resetFileCounters(); }, 60e3 * 5);


I kneel before your grandness. I shall have it inserted and report back in a few days. Thank you once again.


No need to kneel :smiley:

Let me know if this does the trick or if you really need it to reset a certain time of the day. The trickiness with that is there will always be some deviation and if the bot is down, it just has to be coded to do it when the bot starts up if a window was missed.



From what I can see it does not appear to be working. We let it run course for a few days to confirm but the counter within !setwins remains.


See above, I made an adjustment. As I said, I didn’t test it, and there were missing parenthesis. I wrapped a return value as integer as well to keep with integers and not have any floats.


Happy to report it appears to work! Thank you once again :slight_smile:


You bet. I should have actually ran the script instead of typing it in a text editor and hoping for the best. Hopefully the every 24-hours bit works for you.