如何让 Discord 机器人检测表情符号反应并单击(触发)它



所以我的问题是

场景: 假设我的服务器中有一个机器人发送标题为"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

最新更新