使用discord.io将消息发送到特定频道

时间:2019-04-29 14:43:38

标签: javascript node.js discord.io

使用Discord.io,我试图将消息发送到与发送消息不同的通道,但是经过大量的Google搜索和尝试之后,我似乎仍然找不到找到这种方法的方法。

我试图简单地将channelID更改为想要发送到的频道,并覆盖该channelID到我希望发送到的频道,但是没有成功

例如:


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;
        }
    }
});

希望您能帮助我。 如果您有不清楚的地方,请随时询问。

谢谢。

1 个答案:

答案 0 :(得分:0)

因此,我在文档中指出channelID为Snowflake的原因不起作用。我不知道的是,这看起来很像普通字符串。因此,当我尝试用字符串覆盖channelID时,它似乎起作用了。像这样:

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;
        }
    }
});