【问题标题】:Error when wanting to read the messages of a specific channel想要读取特定频道的消息时出错
【发布时间】:2019-07-06 14:42:35
【问题描述】:

我正在尝试“调节”一个频道,在这个频道中应该只能发送某些命令,当他们发送与允许的命令或消息不同的命令或消息时,我会发送一条消息警告它。我有条件的审核逻辑,但我的问题是我无法获得在该频道上发送的消息(在该特定频道上写作的任何人)

执行代码时,它在控制台中没有显示任何内容,这意味着它无法识别他们在该通道中发送的消息:(

代码:

client.on("message", (message) => {
  if (message.author.tag === "NAME#1234") {
    if (message.content.startsWith(prefix + "on")) {
      console.log(message.channel.id)
      if (message.channel.id == "361344824500289538") {
        //If the channel where they send the message has the id that I have set, then show me the messages that are sent
        console.log(message.content)
      } else {
        console.log(message.content)
      }
    }
  }
});

【问题讨论】:

  • 我建议为每个if 语句创建一个else 语句来检查代码中哪里出错了。尝试从那里修复它,如果您遇到新问题,请告诉我们

标签: javascript node.js discord.js


【解决方案1】:

假设您希望有一个命令只能在一个频道中使用(这可能是 /meme 用于名为“memes”的频道)。如果该命令在其他地方使用,机器人会说“此处不允许命令!”

代码如下:

client.on("message", message => {
     if (message.content.startsWith('/meme') {
         if (message.channels.find(c => c.name ===! 'memes') {
              message.reply("Command Not Allowed Here!")
        } else {rest of meme command script}
     }
}

【讨论】:

    猜你喜欢
    • 2021-12-27
    • 2020-12-03
    • 2020-06-29
    • 2020-05-17
    • 2019-11-26
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 2021-07-06
    相关资源
    最近更新 更多