Specific user command (script)


Continuing the discussion from Restrict Sounds to single person:

At the moment I’m trying to play around with making a custom script command restricted to a particular user.
I’m not an expert, by far, but I’m aware that this part of a script (specifically the ‘7’ in this case) defines which permission group has access to it.

Is there any way to change this so that instead of a group, it can also look for the command sender name?

$.registerChatCommand('./custom/nameofscript.js', 'commandname', 7);

In the above linked topic, it was suggested:

“Why not give those “long-term” users the Regular role and then give them a regular-only command?”

I’m not sure this would be a solution either, as the command user would also be a subscriber or moderator. So surely the bot would just override the regular group and reasign the higher tier group? Not to mention mods could have issues with editing things with the bot if needed.

I have also attempted editing the database and adding an additional group per special command user, but it seems the bot rewrites the group number if that’s changed. So I couldn’t add anything in between moderator and subscriber as desired. The only working group additions were those numbed above 7.

I’m not sure if it’s just a case of checking the sender name in the If statement (and keeping the perm group as 7), but again, I’m not experienced with the code so I’m not sure if that’s even possible.

(function() {
$.bind('command', function(event) {
    var sender = event.getSender(),        
        command = event.getCommand(),

    if (command.equalsIgnoreCase('commandname')) { // check name here? maybe
        if (action === undefined || subAction === undefined) {
            $.say($.whisperPrefix(sender) + "Command content here");
$.bind('initReady', function() {
    $.registerChatCommand('./custom/nameofscript.js', 'commandname', 7);
}); })();

Any help with this would be greatly appreciated…
I’m also using this as a learning process, so apologies if I’m missing something really obvious here. :sweat_smile:


How do you want this system to work?

Do you want exclusive commands for certain people? I.E: UserA gets command “123” and UserB gets command “456”. Or all permitted users get access to both commands “123” and “456”?


Hey :slight_smile:

I was hoping for the first, where User A and B have separate commands, exclusive to them individually…


Well. I’m having a hard time of thinking of a dynamic way to achieve that, at least without possibly putting extra load onto the bot (in bigger channels that is).

I would say the easiest way would be to do a huge series of If/Else statements, similar to what you have already. Problem is you’ll have to restart the bot for each new user’s command.

The dynamic way would involve storing the username, command name, and command data, all in the database. This would be less flexible in the sense that features are limited to what’s programmed (I.E it’s just be a command with a response, maybe squeeze in a sound somehow), unless you were to copy the format of the existing customCommand parsing.

I.E: The table name would be the user’s twitch. And then in JSON format it would have the command name and response in it.

The thing is, for that system to work you’d have to either loop through the table when every command is done (which could make the bot’s response time SLOWER for ALL commands)… Or somehow register the commands on bot launch.


Hmm, ultimately what I’m trying to achieve is a few people being able to trigger a personal audio hook.
There’s only a handful of people and it’s not something that would be added to very often, so restarting the bot / having to code in each new user is totally fine. It doesn’t have to be too elegant.

Do you know how I would do this and check a username within an If statement?
Basic logic being:

if (command.equalsIgnoreCase('command')) && sender == "specialusername"

which if true, would trigger



That could work, but you’d be better off using equalsIgnoreCase like you see for the command.

the two == is a comparison operator that returns true if both objects are the same. So if the username was AbCdEfG but you put `== “abcdefg”, it wouldn’t return true.


So basically you want something like this:

if (command.equalsIgnoreCase('command')) && sender.equalsIgnoreCase('a username')) ) {

That way only when command is typed by a username the if statement will fire. Otherwise the code moves right past it onto the next.


Great, seems like I have it all working now. It suddenly all makes sense :smile: Thanks…

Played around with a few things and have more-or-less made what I was also looking to create, an audio hook only intro for special users. Whether it’s the most efficient or performance optimal way or not, I have no idea. But either way I’ll go with it.
I just need to add something that checks if the stream is live before firing the audio hooks / updating the ‘trigger flags’, and resets them automatically when it goes offline.

(function() {

var specialintrotrigger = false;

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

    var command = event.getCommand();
    var sender = event.getSender();

    // Just for testing purposes, while I work on automating it.
   if (command.equalsIgnoreCase('resetintros') && sender.equalsIgnoreCase('CasterName')){
        specialintrotrigger = false;
        $.say(sender + ' has reset the intro triggers.');
        $.consoleLn('All intro triggers set to false!');


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

    var sender = event.getSender();
    if (sender.equalsIgnoreCase('specialname')) {
        if (specialintrotrigger === false) {
            specialintrotrigger = true;
            $.consoleLn(sender + ' has spoken - Triggering audio hook!');

$.bind('initReady', function() {
    $.registerChatCommand('./custom/introSystem.js', 'resetintros', 1);



There’s 2 events you can use to detect when the stream is online and offline:

$.bind('twitchOnline', function(event) {
$.bind('twitchOffline', function(event) {

You can use these to set a boolean to true/false.


You can use $.isOnline($.channelName) in an if statement. Such as:

if(!$.isOnline($.channelName)) {

Since the above code has ! before $.isOnline($.channelName), it is checking if it returns FALSE, aka that you’re offline. The return; statement will stop the code from continuing.


Awesome. I’ll see what I can do :slight_smile:
Seems relatively straightforward…

Thank you!


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