Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用discord.io将消息发送到特定通道_Javascript_Node.js_Discord.io - Fatal编程技术网

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

Javascript 使用discord.io将消息发送到特定通道,javascript,node.js,discord.io,Javascript,Node.js,Discord.io,使用Discord.io,我试图将消息发送到不同的频道,而不是发送消息的频道,但经过大量的谷歌搜索和实验,我似乎仍然找不到这样做的方法 我试图简单地将channelID更改为我希望它发送到的频道,并将channelID覆盖到我希望它发送到的频道,但没有成功 例如: bot.on('message', function (user, userID, channelID, message, evt) { if (message.substring(0, 1) == '!') {

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

希望你能帮助我。 如果你有什么不清楚的地方,尽管问


提前感谢。

所以我找到了它不起作用的原因,在文档中说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;
        }
    }
});

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

您能否确认默认案例成功运行,并向bot正在侦听的通道发送消息?你能展示一下你用来获取你想要发送消息的另一个频道的频道ID的代码吗?@spoticouscompiler我已经解决了这个问题,但仍然感谢你试图帮助我。它还不允许我将其设置为解决方案(等待2天?),但在可能的情况下会这样做。您是否可以确认默认案例成功运行,并向bot正在侦听的频道发送消息?你能展示一下你用来获取你想要发送消息的另一个频道的频道ID的代码吗?@spoticouscompiler我已经解决了这个问题,但仍然感谢你试图帮助我。它还不允许我将其设置为解决方案(等待2天?),但在可能的情况下会这样做