node-irc icon indicating copy to clipboard operation
node-irc copied to clipboard

TypeError: self.connect is not a function

Open pta2002 opened this issue 7 years ago • 2 comments

I'm trying to create a client, but it fails before even connecting.

Version: 0.5.2 Code:

const irc = require('irc')

let client

let server = 'irc.[server hidden].com'
let nick = 'nick'
let channels = ['#channel']

client = irc.Client(server, nick, { channels: channels, debug: true })

client.addListener('message', (from, to, msg) => {
  console.log(`${from} => ${to}: ${msg}`)
})

client.addListener('error', (message) => {
  console.log('error: ', message)
})

client.connect()

Trace:

/home/username/projects/bot/node_modules/irc/lib/irc.js:107
        self.connect();
             ^

TypeError: self.connect is not a function
    at Object.Client (/home/username/projects/bot/node_modules/irc/lib/irc.js:107:14)
    at Object.<anonymous> (/home/username/projects/bot/paib.js:9:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

I looked at the source, and there doesn't seem to be any definition of self.connect.

pta2002 avatar Jul 28 '17 22:07 pta2002

I made the same mistake, you wrote "client = irc.Client(...)" instead of "client = new irc.Client(...)"

422404 avatar Aug 24 '17 01:08 422404

I have the same problem with new Client(...):

try{
var c = new Client("irc.freenode.net", "KaiOS", {
                                                    userName: "k",
                                                    realName: "Moo",
                                                    autoConnect: true,
                                                });
setTimeout(function(){c.join("##pcworms");}, 3000);
c.addListener('message', function(nick, to, text, msg){
    document.write("<" + nick + "> " + text + "<br>");console.log(text);});
}catch (e) { console.log(e); }

Using the same version as pta2002

farooqkz avatar Jun 27 '19 06:06 farooqkz