簡體   English   中英

如何讓 Discord Bot 檢測表情符號反應並單擊(觸發)它

[英]How can I make Discord Bot detect emoji reaction and click(trigger) it

所以我的問題是

場景:假設我的服務器中有一個機器人發送標題為“Hello”的嵌入消息,並在其下添加一個隨機反應,其作用類似於觸發器。

我想要做什么:我希望我的機器人檢測該嵌入消息的標題,如果它與我的 if 語句匹配,那么它還會單擊/添加與嵌入機器人放在它下面的相同反應。 如果有任何困惑,請告訴我。

此代碼僅適用於新消息和緩存消息,

client.on("messageReactionAdd", (reaction, user) => {
  const message = reaction.message;
  const embeds = message.embeds;
  //return if no embeds or if another user reacted instead of the bot itself
  if(!embeds.length || user.id !== message.author.id) return;

  const firstEmbed = embeds[0];

  //add your logic here
  if(firstEmbed.title !== "Hello") {
    //react same
    message.react(reaction.emoji);
  }
});

要過濾掉嵌入,您可能需要參考

https://discord.js.org/#/docs/main/12.2.0/class/MessageEmbed

暫無
暫無

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

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