简体   繁体   English

如何对邮件附件 discord.js 做出反应

[英]How to react to a message attachment discord.js

So what I am trying to do is, my discord bot listens for attachments then takes them and sends them to a particular channel, I want it to also react it with and now I saw some solutions but they require message id and channel id, my channel id would remain the same but my message id would change every time I send an attachment how do I make it so it reacts to the attachment into that channel所以我想要做的是,我的 discord 机器人侦听附件然后将它们发送到特定频道,我希望它也能对其做出反应,现在我看到了一些解决方案,但它们需要消息 ID 和频道 ID,我的频道 ID 将保持不变,但每次我发送附件时我的消息 ID 都会更改我如何制作它以便它对进入该频道的附件做出反应

My code:-我的代码:-

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('👎'))
    }
  });
})

I have tried yes.react('') but it does not work and replies with yes.react is not a function我已经尝试过yes.react('')但它不起作用并回复yes.react is not a function
Would be grateful if someone helps me with this.如果有人帮助我,将不胜感激。

Channel#send returns a promise. Channel#send返回 promise。 Meaning we can use an asynchronous function in order to define the channel sending method using await (Send the message before defining it), and have our bot react to the newly sent message.这意味着我们可以使用asynchronous function来定义使用await的通道发送方法(在定义之前发送消息),并让我们的机器人对新发送的消息做出反应。

Final Code最终代码

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('👎')
    }
  });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM