javascript - 想读取特定 channel 的消息时出错

标签 javascript node.js discord.js

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

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

代码:

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

最佳答案

假设您想要一个仅在一个 channel 中使用的命令(对于名为“memes”的 channel ,这可能是/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}
     }
}

关于javascript - 想读取特定 channel 的消息时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54658774/

相关文章:

javascript - 如何以可扩展的方式分配 javascript 变量

javascript - 正则表达式从 youtube url 中提取视频 ID 或播放列表 ID

node.js - Sails 套接字 io 连接到与传入的 URL 不同的 URL

json - 当我执行 npm install 时,Git Clone 的权限被拒绝

canvas - 如何在嵌入的 discord 中编辑图像?

javascript - pm 2 启动了我的机器人,但该机器人未在 Discord 上在线

javascript - 如何解析从 Datatables ajax 调用接收到的 JSON?

javascript - 无法调用该函数,即使它已加载。

node.js - Express - res.send() 工作一次

javascript - 数据库中的信息有多本地化?