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?