Trying to get a way for bot to join channels through oauth

I’ve gotten a little bit of guidance, but don’t have the full picture yet, here’s what I am trying to accomplish :

I created a bot in nodejs. I have that bot registered as an application in Twitch. I have the application set up to oauth a user to add the app, and the scope set for channel messages and whispers. What I need to accomplish is to get the bot to join the channel of the person oauthing in, or in some way make it join a channel.

I am using tmi.js for the nodejs bot, and I know I can add a channel to join that way, but what someone mentioned is that there was a way to make it join a channel through the oauth (but the help was a little vague so not positive). I am just trying to understand what my options are here and the best way to go about this.

Also, someone mentioned something about an “auto-join” database for the bot, and it would also be great if anyone has knowledge of what that is and how it works (mentioned here - [JAVA] Adding a bot to the user's channel once the app has been authenticated to their channel) .

There’s 2 ways to get a bot to join a channel with the tmi.js library, either specifying that channel in the options you connect with, or using the client.join(channel) function.

If you want the bot to join their own channel then you would simply put that channel in the channels array options, or just client.join(channel) if it’s already connected. If you don’t know what the username is that the bot is connected as you can use the User Access token with the Get Users endpoint https://dev.twitch.tv/docs/api/reference#get-users to retrieve the username and then join to that.

1 Like

Thanks for the reply @Dist. So I am to understand that there’s no way to really accomplish this through the oauth directly, but only from within the bot code itself. It looks like the authentication is a layer that just enables the bot to be added to the channel, and from there I need to deal with actually adding it to the channel via nodejs/bot code.

I was reading that people oftentimes have a !join command that people execute in their channel once the app is authenticated, or something similar, so I’ll look into that, or alternatively have a closed endpoint to get the bot to join via the oauth return url. as for getting the bot to rejoin I think sqlite should be fine for keeping track of the channels.

Authentication is the “password” for a “username/password keypair” that lets the “user” join the chat server.

Once you have joined the chat server you can join any channel/room you like.

This is essentially the same as how a “regular IRC” bot works.

This is more for a multi channel join where the have a user, say “nightbot” to use a real world example

And nightbot connects to chat and it’s own channel and then people can make nightbot join their own channel by going to nightbot’s channel and running !join

An alternative is you have an oAuth for your bot, users go to your bots website, login with their Twitch and you have a join button, when thats pressed, you tell your bot to join that channel.

For both examples you are telling your bot to perform a JOIN command, and this works whether you have an oAuth and are logged into chat as a real user, or if you have anon connected to chat and used no oAuth

1 Like

Hey thanks for the help everyone. I have the bot integrated and up and running. What I ended up doing was using express to make an endpoint running in the bot script, to add the bot, and one to remove the bot. Basically the user just clicks a link “add the bot”, and the oauth calls the endpoint of the bot and stores the channel/user name in a sqlite db and joins the channel. When they click the “remove bot” link it removes the entry from the db and leaves the channel. I’d like to make it so if they kick the bot tmi sees that they got kicked and deletes them from the db that way, but need to look into this more. I didn’t plan on using a db, but since I am I also added a column for “date added”. Might as well get some metrics from it. If you feel like trying out the bot in your Twitch channel you can do it from https://tipit.io/help. The available commands for the Twitch bot are also on that page.

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