当前位置: 代码迷 >> JavaScript >> 想要读取特定频道的消息时出错
  详细解决方案

想要读取特定频道的消息时出错

热度:7   发布时间:2023-06-03 18:13:26.0

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

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

代码:

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

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

这是代码:

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}
     }
}
  相关解决方案