# Connect bot to new channel via function?

**URL:** <https://discuss.dev.twitch.com/t/connect-bot-to-new-channel-via-function/19939>\
**Category:** Chat and IRC\
**Created:** [February 8, 2019, 2:17pm UTC](https://discuss.dev.twitch.com/t/connect-bot-to-new-channel-via-function/19939 "2019-02-08T14:17:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dantribefire](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dantribefire/32/6093_2.png) [@dantribefire](https://discuss.dev.twitch.com/u/dantribefire)\
**Post date:** [February 8, 2019, 2:17pm UTC](https://discuss.dev.twitch.com/t/connect-bot-to-new-channel-via-function/19939/1 "2019-02-08T14:17:48Z")

</div>

Hi all. I have created a bot, that on initialising is able to start following an array of channels. Pretty standard stuff. However, I’m struggling to figure out how I could call a function after the bot has been initiated which would give it a new channel to follow, without having to reboot it. The main issue with rebooting it, of course, is that it then takes time to connect individually to each channel - and of course any function it was running would be stopped.

For reference, I am using twitch.js (similar to tmi.js) - with a fairly standard setup. Is there some function I am missing that can add an extra channel for it to join?

Any help extremely appreciated!

Cheers,  
Dan

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [February 8, 2019, 2:19pm UTC](https://discuss.dev.twitch.com/t/connect-bot-to-new-channel-via-function/19939/2 "2019-02-08T14:19:26Z")

</div>

> [@dantribefire](#):
>
> Hi all. I have created a bot, that on initialising is able to start following an array of channels

You mean following or joining the chat to send/receive messages of that channel? Your OP is unclear.

If it’s chat then you just need to use the join command for the library.

Better of checking with the devs of `twitch.js` as this is a general forum for Developers not the `twitch.js` support forums

---

<div class="post-metadata">

**Author:** ![QuaranteTrois](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/quarantetrois/32/5766_2.png) [@QuaranteTrois](https://discuss.dev.twitch.com/u/QuaranteTrois)\
**Post date:** [February 9, 2019, 12:51am UTC](https://discuss.dev.twitch.com/t/connect-bot-to-new-channel-via-function/19939/3 "2019-02-09T00:51:28Z")

</div>

I don’t use twitch.js, but it seems you have to do :

```
chat.join(channel1).then(channelState => { }) 
chat.join(channel2).then(channelState => { }) 
chat.join(channel3).then(channelState => { }) 

```

With pureJS and Websocket ([=\> Like the chatbot.js example](https://github.com/twitchdev/chat-samples/blob/master/javascript/chatbot.js#L59)) you have to do :

```
webIRC.prototype.onOpen = function onOpen() {
    const socket = this.webSocket;
    if (socket !== null && socket.readyState === 1) {
        socket.send('CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership');

        socket.send('PASS ' + this.password);
        socket.send('NICK ' + this.username);
        socket.send('JOIN ' + this.channel);

        [
            "dakotaz", "csgomc_ru", "csgomaincast", "Thijs", "IWillDominate",
            "fextralife", "GSL", "Greekgodx", "CDNThe3rd", "SilverName", "Gosu",
            "stylishnoob4", "ALOHADANCETV", "Solary", "JakenbakeLIVE", "JoshOG",
            "LexVeldhuis", "gammaray_tv", "KingRichard", "Trymacs", "jovirone",
            "BurkeBlack", "Loeya", "just_ns", "GodHunt", "singsing", "fps_shaka",
            "uzra", "Sacriel", "DreadzTV", "DreamLeague", "SovietWomble", "Sick_Nerd",
            "UCCleague", "BreaK", "C_a_k_e", "mandiocaa1", "TidesofTime"
        ].forEach((v) => socket.send(`:{this.username}!{this.username}@{this.username}.tmi.twitch.tv JOIN #${v}`));
```

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [February 9, 2019, 10:30am UTC](https://discuss.dev.twitch.com/t/connect-bot-to-new-channel-via-function/19939/4 "2019-02-09T10:30:18Z")

</div>

Closed on February 9, 2019, 10:30am UTC


