Emotesets

Fetching emotesets whenever they are updated can be relatively simple. We might use this if we were listing available emoticons and always want to keep them up to date.

Add a quick extension that watches for a change and fetches the new emotes from get emoticons by set.

twitch.chat.on('USERSTATE', checkEmotesets);
twitch.chat.on('GLOBALUSERSTATE', checkEmotesets);

async function checkEmotesets (msg) {
    // look for new emotesets
    if (!Array.isArray(msg.tags.emoteSets)) {
        return;
    }

    const emotesets = msg.tags.emoteSets.join(',');

    // emotesets haven't changed
    if (twitch.chat.emotesets === emotesets) {
        return;
    }
    twitch.chat.emotesets = emotesets;

    // fetch
    const result = await twitch.api.request('/chat/emoticon_images', {
        data: { emotesets },
        kraken: true
    });

    // emit result
    handleEmotesets(result.emoticonSets);
}

function handleEmotesets (emotesets) {
    // updated emotes arrived!
}

Quick tip: Emote urls are https://static-cdn.jtvnw.net/emoticons/v1/${id}/1.0 where ${id} is your character code id.