Closed WarCatStudios closed 2 years ago
I figured it out, it's not a tmi.js thing its a javaScript documentation thing. For those of you are are curious it is the forEach()
function.
Here is my code now
function startChannelLeave(userstate, message, channel){
var currentChannels = (client.getChannels());
console.log(currentChannels);
currentChannels.forEach(function (e) {
console.log(e);
leaveFreeChannels(userstate, message, channel, e);
});
CHANNEL_NAMES.forEach(function (e) {
rejoinPremiumChannels(userstate, message, channel, e);
});
}
function leaveFreeChannels(userstate, message, channel, e){
client.part(e)
.then((data) => {
// data returns [channel]
}).catch((err) => {
return;
});
}
function rejoinPremiumChannels(userstate, message, channel, e){
client.join(e)
.then((data) => {
// data returns [channel]
}).catch((err) => {
return;
});
}
e
is the variable that contains the array to be passed onto the funtion
Situation I am creating a function that uses
client.getChannels()
to first get an array of every channel my Twitch bot is joined to, then to second, usepart()
to leave all those channels in the array. Finally the bot is supposed to usejoin()
to rejoin a few at the end of the function.Function
Things to note about the function
ADMIN_CHANNELS
is the variable that stores the array of the channels to rejoincurrentChannels
is the variable that stores all channels currently joinedActual behaviour: Every time the function is run I get the error message seen below. I've noticed that this is triggered when I place an array or a variable containing an array inside of the parenthesis of
join()
andpart()
Expected behaviour: The function should leave every single channel that the bot is currently joined to and then rejoin from an array of a few selective channels,
Error log:
Server configuration