Api help - Update Twitch Notification Bot

Hi everyone,

My Discord server has been relying on a discord bot (see below) for a little while now, and I got the email about the api changing in September to v5 and was wondering if anyone here could help guide me through the process of updating to the new api.

Bot code : https://github.com/etacarinaea/discord-twitch-bot/blob/master/index.js

My Javascript knowledge is passable at best; I have a old Twitch ClientID from before March, and I know that I need to change the Accept: "application/vnd.twitchtv.v3+json" to v5, but I’m unsure of what else I need to do; that alone doesn’t seem to work and the bot no longer posts notifications about streams going live anymore.

The ClientID and Discord bot token are passed as arguments when I run the bot.

    try {
        var apiPath;
        if(getStreamInfo){
            apiPath = "/kraken/streams/" + twitchChannel.name.trim();
        }else{
            apiPath = "/kraken/channels/" + twitchChannel.name.trim();
        }
        opt = {
            host: "api.twitch.tv",
            path: apiPath,
            headers: {
                "Client-ID": twitchClientID,
                Accept: "application/vnd.twitchtv.v3+json"
            }
        };
    }
    catch(err){
        print(err);
        return;
    }

You have to swap the header for the v5 header and swap the apiPath to use the UserID of the channel instead of the UserName of the channel

You may consider switching over to Webhooks instead

How do I get the UserID? I can see the variable apiPath in the if / else statement, the only part I’m lacking right now is what to change for the apiPath; How do I get the IDs? Or do I just replace TwitchChannel.name.trim with TwitchChannel.id.trim ?

Your reply suggests you didn’t write the initial code, so you might have issues making all the changes. Since I’m not giving the full answer but links to the documentation so you can fix it yourself

You will need to either follow what the migration guide says

https://dev.twitch.tv/docs/v5/guides/migration/#username-versus-user-id

Of what the Twitch API v5 Gude says

For converting from a name to a ID.

The code suggests that a command of !add username is run in discord. You’ll need to add code to take that username and convert it to a userID and store that along with the channelName

Yeah I didn’t write it; Basically our server isn’t being run by the owners properly, and somehow all of this stuff has been left to me to do, even though we have an experienced coder as another staff member, but he refuses to do anything. I’m trying to learn this as I go so our members aren’t suddenly left in the dark.

Thanks for the help so far, I’ll see if I can get it working.

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