Unable to .join() a .part()'ed channel

Using TMI.JS, I am dynamically getting a list of channels for my bot to join from a MySQL database.

A user signs up on my site and can add their channel (all handled with Twitch Auth flows) to a db that my node.js (using tmi.js) app checks every X seconds for channels to join/leave.

If it’s running, and I add a new channel, it works just fine. The new channel gets added right away. But when I part a channel (which also works), if I try and .join() the channel again, I get “No Response From Twitch”.

const opts = {
		identity: {
			username: 'redactedbot',
			password: `oauth:${process.env.REDACTED_TOKEN_NAME}`
		},
		options: {
			debug: true,
		},
		channels: await getJoinedTwitchChannels()
	};

That’s how I get my tmi client set up, it’s been working perfectly.

I’ve got this updating function on an interval:

async function updateBotChannels(){
		let databaseChannels = await getJoinedTwitchChannels();
		let joinedChannels   = vespi.getChannels();

		console.log( 'Channels from DB (wanted): ', databaseChannels ); // ['#a','#c','#d']
		console.log( 'Channels from TMI (joined): ', joinedChannels );  // ['#a','#b','#c']

		let channelsToJoin  = databaseChannels.filter(value => !joinedChannels.includes(value));            // ['#d']
		let channelsToLeave = joinedChannels.filter(value   => !databaseChannels.includes(value)); // ['#b']

		channelsToLeave.forEach(async channel => {client.part(channel.replace('#',''))});
		channelsToJoin.forEach(async channel  => {client.join(channel.replace('#',''))});
	}

It parts the channels just fine:

[22:42] info: Executing command: PART #b
[22:42] info: Left #b
Parted #b
[22:42] info: [#b] <REDACTEDBOT>: See ya later!

And joining works well as well, unless it was parted first. Is there a cooldown time I overlooked in the docs between parting and rejoining? Do I need to .disconnect() and .connect() the client again?

Is this an issue with tmi.js, perhaps?

It looks like when I .join(), it works. Then .part(), it works. Then if I .join() again after parting (regardless of how long between joins and parts), it just never gets added to the client.channels array. So it keeps issuing the JOIN #target command.

But, on the target channel, the bot eventually shows up and starts responding to commands - so I assume it’s getting through, just never added to the tmi.js client.channels array for some reason if it parted first.

Is there an (inexpensive?) way to get a list of all the channels a user (bot) is active in?

You track it internally in your code, if the library you are using (if any) doesn’t do it for you.

TMI (the service not the lirbary) doesn’t provide a command to call for “where am I”/“what am I connected to”, since in 99% of cases the connection you have to chat is only in one room, the one the user is watching in their browser.

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