簡體   English   中英

如何對郵件附件 discord.js 做出反應

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

所以我想要做的是,我的 discord 機器人偵聽附件然后將它們發送到特定頻道,我希望它也能對其做出反應,現在我看到了一些解決方案,但它們需要消息 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
如果有人幫助我,將不勝感激。

Channel#send返回 promise。 這意味着我們可以使用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('👎')
    }
  });
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM