Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call method 'match' of undefined #326

Closed
ReidandKat opened this issue Feb 11, 2015 · 7 comments
Closed

Cannot call method 'match' of undefined #326

ReidandKat opened this issue Feb 11, 2015 · 7 comments

Comments

@ReidandKat
Copy link

I am getting error: Cannot call method 'match' of undefined
When I attempt to 'say' to a channel

Here is my code:

var bot = new irc.Client(config.server, config.nick, config);
bot.say('#imaqtpie', "test");

The bot successfully connects to the channel because I can see the chat messages in the log.

Full error:

TypeError: Cannot call method 'match' of undefined
at Client._splitLongLines (/var/www/node_modules/irc/lib/irc.js:931:11)
at /var/www/node_modules/irc/lib/irc.js:967:36
at Array.forEach (native)
at Client._speak (/var/www/node_modules/irc/lib/irc.js:966:12)
at Client.say (/var/www/node_modules/irc/lib/irc.js:953:10)
at Socket. (/var/www/server.js:39:13)
at Socket.emit (events.js:106:17)
at Socket.onevent (/var/www/node_modules/socket.io/lib/socket.js:330:8)
at Socket.onpacket (/var/www/node_modules/socket.io/lib/socket.js:290:12)
at Client.ondecoded (/var/www/node_modules/socket.io/lib/client.js:193:14)

@ReidandKat
Copy link
Author

the config includes the channel to join, do I need to also specify it in the say command?

@ghost
Copy link

ghost commented Feb 11, 2015

On Wed, Feb 11, 2015 at 10:23:49 -0800, ReidandKat wrote:

I am getting error: Cannot call method 'match' of undefined
When I attempt to 'say' to a channel

Here is my code:

var bot = new irc.Client(config.server, config.nick, config);
bot.say('#imaqtpie', "test");

Hi ReidandKat,

This is not enough information to debug with. Presumably you're
waiting for the registered or motd event before trying to
send to the channel? You're going to need to do this to ensure
that the client has fully negotiated its connection to the server
and joined the channel by the time you try to send the message.

Additionally, you have only included a snippet of your code. You
are not providing the definition for the config object, so it's
impossible to determine if things are configured properly or what
the problem could be. It's always more helpful to provide all of
your code when asking for help instead of the snippet that you
think is relevant--if you were right in determining the relevant
bits, you'd be able to find the problem, and thus you wouldn't
need to ask for help.

Chris Nehren

@nuclearace
Copy link

I too am getting this crash.

TypeError: Cannot read property 'match' of undefined
    at Client._splitLongLines (/Users/me/Desktop/CytubeBot/node_modules/irc/lib/irc.js:929:10)
    at /Users/me/Desktop/CytubeBot/node_modules/irc/lib/irc.js:965:36
    at Array.forEach (native)
    at Client._speak (/Users/me/Desktop/CytubeBot/node_modules/irc/lib/irc.js:964:12)
    at Client.say (/Users/me/Desktop/CytubeBot/node_modules/irc/lib/irc.js:951:10)
    at IRCClient.sendMessage (/Users/me/Desktop/CytubeBot/lib/ircclient.js:72:14)
    at CytubeBot.handleChatMsg (/Users/me/Desktop/CytubeBot/lib/cytubebot.js:623:12)
    at Socket.<anonymous> (/Users/me/Desktop/CytubeBot/lib/bothandlers.js:17:7)
    at Socket.Emitter.emit (/Users/me/Desktop/CytubeBot/node_modules/socket.io-client/node_modules/component-emitter/index.js:134:20)
    at Socket.onevent (/Users/me/Desktop/CytubeBot/node_modules/socket.io-client/lib/socket.js:254:10)

Creating the client as:

this.client = new irc.Client(this.ircServer["server"], this.nick, {
        debug: true,
        userName: "CytubeBot",
        autoConnect: false,
        channels: [self.channel],
        port: this.ircServer["port"]
    })

sendMessage is just

IRCClient.prototype.sendMessage = function(message) {
    this.client.say(this.channel, message)
};

@jengel3
Copy link

jengel3 commented May 16, 2015

Hey, @nuclearace, did you ever figure out this crash? I'm getting this same error now, and I'm not sure what's causing it.

cc. @ReidandKat

@otse
Copy link

otse commented May 28, 2015

Yeah this is odd

@Xaekai
Copy link

Xaekai commented Jun 2, 2015

@Jake0oo0

Resolution was as simple as catching the error and doing nothing with it.

@mixaildudin
Copy link

As far as I understand, this happens when you're trying to send a message when your Client instance is not fully initialized yet.
After looking at the source I found the solution that helped for me:

var bot = new irc.Client('my.irc.server.com', 'botName', {
    autoConnect: false // with auto connect enabled we can't tell when the initialization projecc is complete
});
/* but if we connect manually like here, we have a convenient callback function telling us that when we can start sending our messages */
bot.connect(5, function() {
    bot.say('mixaildudin', 'how's it going?');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants