tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 214 forks source link

i want to know how to make a mod only command. #283

Closed matt332 closed 6 years ago

matt332 commented 6 years ago

I would have thought that it would be as simple as saying ''if(user.mod),, around the command response but apparently not, i have read through the doccumentation and it doesnt say how to create it can somebody help

AlcaDesign commented 6 years ago

Personally my bot uses this with 100% accuracy:

if(user.mod || user['user-type'] === 'mod') {
    // Something mod only
}
matt332 commented 6 years ago

I am trying to make a shout out command for a mod only and that ^ didnt seem to work can i please have some help help

matt332 commented 6 years ago

Here is an example of my code client.on("chat", function(channel, user, message, self){ if(user.mod || user['user-type'] === 'mod') { if(message.startsWith("!so")){ var input = message.split(' ')[1]; client.say("matty70988", "Go check out the wonderful " + input + " over at htpp://twitch.tv/" + input); }; }; });

AlcaDesign commented 6 years ago

You may also want to check that the broadcaster can use it. They are not considered a moderator in the chat.

let isMod = user.mod || user['user-type'] === 'mod';
let isBroadcaster = channel.slice(1) === user.username;
let isModUp = isMod || isBroadcaster;

Then use isModUp for command checking:

if(isModUp) {
    // Something for moderators or higher
}
matt332 commented 6 years ago

oh

AlcaDesign commented 3 years ago

@NitchgamingStudios WIthin a message event handler.

Don't use this issue as a general JavaScript programming forum. You can join the Twitch API Discord Server and chat in the #general-javascript channel or #tmi channel.