无法将Discord.js漫游器命令绑定到特定通道

时间:2020-01-23 20:39:41

标签: discord discord.js

我找不到任何方法可以解决所有通道可使用的所有命令的问题。我正在创建一个机器人 允许您在Discord中玩“街机”游戏。

...
client.on('message', (msg) => {
    if (message.channel.id != config.singleChannelID) return; // I tried using this, as recommended by other users but I don't know where to put ChannelID.

    let prefixd = 'd!'
    if (!msg.content.startsWith(prefixd)) return

    let command = msg.content.toLowerCase().slice(prefixd.length).split(" ")[0]

    if (command == '20') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 20) + 1}**!`)
    if (command == '12') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 12) + 1}**!`)
    if (command == '8') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 8) + 1}**!`)
    if (command == '6') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 6) + 1}**!`)
});

1 个答案:

答案 0 :(得分:2)

您所拥有的可以正常使用,但是您需要将所需的通道ID存储在某个地方(在示例中为配置),或者如果需要可以对其进行硬编码:

if (msg.channel.id != SomeChannelsIdGoesHere) return;

如果您不知道如何获取频道ID,请咨询discord support pages

此外,请注意,您使用的标识符“ message”代替了事件回调中出现的“ msg”。