【问题标题】:Send message to specific channel with discord.io使用 discord.io 向特定频道发送消息
【发布时间】:2019-05-02 03:50:52
【问题描述】:

使用 Discord.io,我试图将消息发送到与发送消息不同的频道,但经过大量谷歌搜索和试验后,我似乎仍然找不到这样做的方法。

我尝试简单地将 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;
        }
    }
});

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

提前致谢。

【问题讨论】:

  • 您能否确认默认情况下工作成功,向机器人正在侦听的频道发送消息?您能否出示用于获取您希望向其发送消息的其他频道的频道 ID 的代码?
  • @ConspicuousCompiler 我已经解决了这个问题,但仍然感谢您尝试帮助我。它还不允许我将其设置为解决方案(等待 2 天?),但会在可能的情况下这样做

标签: javascript node.js discord.io


【解决方案1】:

所以我发现了它为什么不起作用,在文档中它说 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: '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;
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-02
    • 2021-08-21
    • 2020-04-04
    • 2018-12-09
    • 2022-01-08
    • 2021-01-26
    • 2021-01-01
    相关资源
    最近更新 更多