kiwiirc / irc-framework

🛠️ A better IRC framework for node.js. For bots and full clients.
MIT License
182 stars 65 forks source link

how to join a channel and respond to messages? #269

Closed ralyodio closed 3 years ago

ralyodio commented 3 years ago

I'm trying to write a bot, it works when I message the bot but I can't seem to get it to join my channel and respond to events.

Seems like basic stuff that should be in the readme.

I'm using freenode btw

prawnsalad commented 3 years ago

yourbot.join('#channel') There's an example in the readme doing exactly as you mentioned and the full API docs can be found https://github.com/kiwiirc/irc-framework/blob/master/docs/clientapi.md

ralyodio commented 3 years ago

it doesn't work.

ralyodio commented 3 years ago
const IRC = require('irc-framework');
const bot = new IRC.Client();

bot.connect({
    host: 'irc.freenode.net',
    port: 6667,
    nick: 'mywsbbot',
    account: {
            account: 'mywsbbot',
            password: 'asdf1234',
            email: 'chovy@pm.me',
    },
});

bot.matchMessage(/^!stonk/, function(event) {
    console.log(event);
    event.reply(event.message);
});

bot.matchMessage(/^!identify/, event => {
    bot.say('nickserv', 'identify' + bot.options.account + ' ' + bot.options.password, console.log);
});

bot.matchMessage(/^!register/, event => {
    bot.say('nickserv', 'register' + bot.options.account + ' ' + bot.options.password, console.log);
});

bot.matchMessage(/^!join/, function(event) {
    console.log(event);
    const chan = event.message.split()[1];
    bot.join(chan);
});
prawnsalad commented 3 years ago

Try adding the following to see any error messages the network is giving you

bot.on('raw', event => {
    console.log(event);
});
ralyodio commented 3 years ago

nothing obvious but i think its trying to join too early.

prawnsalad commented 3 years ago

Can you paste the raw log?

ralyodio commented 3 years ago

http://sprunge.us/C18vH2

prawnsalad commented 3 years ago

I don't see the !join message being sent to the bot? When are you expecting it to join?

ralyodio commented 3 years ago

i added bot.join('##wallstreetbets') right after bot.connect()