tmijs / tmi.js

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

Check if channel is in emote only chat? #473

Closed Cass-dev-web closed 3 years ago

Cass-dev-web commented 3 years ago

Hey,

Is it possible to check if a channel is in emote only mode?

Thanks!

AlcaDesign commented 3 years ago

The roomstate event will tell you all of the room states and update with changes over time. Here's how you could track it:

const roomstate = new Map();
client.on('roomstate', (channel, state) => {
    if(roomstate.has(channel)) {
        const rs = roomstate.get(channel);
        Object.assign(rs, state);
    }
    else {
        roomstate.set(channel, state);
    }
});
client.on('part', (channel, username, self) => {
    if(self) {
        roomstate.delete(channel);
    }
});

Here's the Twitch Docs on ROOMSTATE https://dev.twitch.tv/docs/irc/tags#roomstate-twitch-tags Then later just check the map to know if it's in emote-only mode.

const channel = '#alca';
if(roomstate.has(channel)) {
    const rs = roomstate.get(channel);
    // "In #alca emote-only is disabled"
    console.log(`In ${channel} emote-only is ${rs['emote-only'] ? 'enabled' : 'disabled'}`);
}

There's also a separate emoteonly event

client.on('emoteonly', (channel, enabled) => {
    console.log(`[${channel}] Emote-only mode ${enabled ? 'enabled' : 'disabled'}`);
});