String to Array for my options->streamer


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);

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:

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

as per

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

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

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

When i make this
var streamer = [];
request(“”, 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:

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.

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

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.

1 Like

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

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