String to Array for my options->streamer


#1

Hello,

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’ ]

i cant use this in my options. Why? :frowning:


#2
  1. This is not TMI.js support
  2. I went to check the docs for you

as per https://docs.tmijs.org/v1.3.0/Configuration.html

You need to use [ ‘#me1’, ‘#me2’ ]

Channel names start with a # for the purpose of third party chat


#3

jea but when i make this
var streamer = ["me1", "me2"];
he connect to me1 and me2

When i make this
var streamer = [];
request(“http://my.page.online/bot/streamer.php”, function(err, res, body) {
streamer = body.substr(0, body.length-2).split(", ");
});
//output for website = me1, me2,
//after substr =
//[ ‘me1’,
// ‘me2’ ]

i think is the same … but ok when i tell my website a “#” befor the name is this output
"
[ ‘#me1’,
#me2’ ]
"

doesnt work :frowning:


#4

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.


#5

oh ok … when i request also asynchronos then it work ?
EDIT: sry i mean synchron


#6

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.


#7

OMG … Thank you so much … it works :heart_eyes::kissing_heart::hugs:
Have a good day :blush: