【问题标题】:How to react to a message attachment discord.js如何对消息附件 discord.js 做出反应
【发布时间】:2021-05-14 21:14:08
【问题描述】:

所以我想要做的是,我的不和谐机器人侦听附件然后将它们发送到特定频道,我希望它也能与 ????和 ????现在我看到了一些解决方案,但它们需要消息 ID 和频道 ID,我的频道 ID 将保持不变,但每次我发送附件时我的消息 ID 都会改变我如何制作它以便它对进入该频道的附件做出反应

我的代码:-

client.on("message", async message => {
  message.attachments.forEach((attachment) => {
    if (attachment.width && attachment.height) {
      if (message.author.bot) return
      let yes = attachment
      const channel = client.channels.cache.find(channel => channel.name === "llllllounge")
      channel.send(yes)
        .then(() => attachment.react('????'))
        .then(() => attachment.react('????'))
    }
  });
})

我尝试过yes.react('????'),但它不起作用并回复yes.react is not a function
如果有人帮助我,将不胜感激。

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    Channel#send 返回一个承诺。这意味着我们可以使用asynchronous function 来定义使用await 的通道发送方法(在定义之前发送消息),并让我们的机器人对新发送的消息做出反应。

    最终代码

    client.on("message", message => {
      message.attachments.forEach(async (attachment) => {
        if (attachment.width && attachment.height) {
          if (message.author.bot) return
          let yes = attachment
          const channel = client.channels.cache.find(channel => channel.name === "llllllounge")
          const msg = await channel.send(yes)
            await msg.react('?')
            msg.react('?')
        }
      });
    })
    

    【讨论】:

    • 嘿,它现在给出了这个错误 const msg = await channel.send(yes) 仅在异步函数中可用
    • 而且当我运行代码时,如果我删除等待,它会说 msg.react() 不是函数
    • 现在都应该修复了。
    • 没问题,我建议接受我的编辑 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2020-09-07
    • 2021-05-26
    • 1970-01-01
    • 2021-07-02
    • 2018-04-03
    • 1970-01-01
    相关资源
    最近更新 更多