With Discord.io I'm trying to send a message to a different channel than what it is sent from, but after a lot of Googling and experimenting I still can't seem to find a way to do so.

I tried to simply change the channelID to the channel I want it to send to and overide the channelID to the channel I want it to send to, but with no success

For example:


bot.on('message', function (user, userID, channelID, message, evt) {
    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0].toLowerCase();

        args = args.splice(1);
        switch(cmd) {
            case 'test':
                bot.sendMessage({
                    to: // channel id here,
                    message: 'If all went well this got sent in another channel'
                });
                break;
            default:
                bot.sendMessage({
                    to: channelID,
                    message: 'I wasn\'t able to understand this command, please try again...'
                });
                break;
        }
    }
});

Hopefully you can help me out. If there is something not clear for you, feel free to ask.

Thanks in advance.

1 Answers

0
Beaconator On Best Solutions

So I found out why it didn't work, in the documentation it says channelID is Snowflake. What I didn't know is that this looks a lot like just a regular string. So when I tried to overide channelID by a string, it seemed to work. Like this:

bot.on('message', function (user, userID, channelID, message, evt) {
    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0].toLowerCase();

        args = args.splice(1);
        switch(cmd) {
            case 'test':
                bot.sendMessage({
                    to: 'your channel id here',
                    message: 'If all went well this got sent in another channel'
                });
                break;
            default:
                bot.sendMessage({
                    to: channelID,
                    message: 'I wasn\'t able to understand this command, please try again...'
                });
                break;
        }
    }
});