i have a big problem. I can connect with this method:
var tmi = require(‘tmi.js’);
const request = require(‘request’);
const fs = require(‘fs’);
var streamer = ["me1", "me2"];
var options = {
options: {
debug: false
},
connection: {
cluster: "aws",
reconnect: true
},
identity: {
username: "my_bot",
password: "oauth:PW"
},
channels: streamer
};
var client = new tmi.client(options);
client.connect();
But i need this:
String to Array
I have a string >> name1, name2, name3, <<
so i make this >> streamer = string.substr(0, string.length-2).split(", "); <<
result is for streamer:
[ ‘me1’,
‘me2’ ]
When are you calling var client = new tmi.client(options); client.connect();?
You’re making a http request which is asynchronous, so if you’re not waiting for the request to finish before connecting then that would explain why it’s not working.
You can either wait for the request to complete be connecting, this will mean when it connects it’ll have the updated channel array. Or you can connect right away, and then when the request finishes use client.join(channel) for each channel you wish to join.