Question

var settings = {
channels : ["#channelname"],
server : "irc.twitch.tv",
port: 6667,
secure: false,
nick : "myBot",
password : "oauth:numbers"
}

var irc = require("irc");

var bot = new irc.Client(settings.server, settings.nick, {
channels: [settings.channels + " " + settings.password],
debug: false,
password: settings.password,
username: settings.nick
});


bot.say(settings.channels, "I'm here!");

console.log("Connected");

This worked yesterday for me, but now it does not show the bot is even in the channel.

In command line I start the script with node scriptname.js and it says "Connected".

Is my config wrong?

Sometimes it connects, others it doesn't. Here are the bot values for when it's running: enter image description here

Was it helpful?

Solution

This is because the connection is happening asynchronously and you're not actually waiting for a connection to occur. It will print "Connected" immediately, but you never actually connected or waited for a connection to happen yet. bot.say will not do anything until you're actually connected!

The proper way to detect if you're connected is to do something like this:

bot.on('registered', function(message) {
  console.log("Connected");

  bot.say(settings.channels, "I'm here!");
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top