NodeJS 无法根据用户React编辑嵌入

r6vfmomb  于 2023-10-17  发布在  Node.js
关注(0)|答案(1)|浏览(122)

我不能更新嵌入一样的用户React使用表情符号上的不和谐机器人。

let avaEmbed = new EmbedBuilder()
        .setTitle(title)
        .setDescription(`\`\`\`plaintext\n${desc}\n\`\`\``)
        .setColor(0x45d6fd)
        .addFields({ name: `Offtank`, value: "Some values here"});

        const reply = await interaction.editReply({ embeds: [avaEmbed] });
        await reply.react(hammer);
        await reply.react(mace);
        await reply.react(ironroot);
        await reply.react(great_arcane);
        await reply.react(one_hand_arcane);
        await reply.react(holy_staff);
        await reply.react(spirit_hunter);
        await reply.react(realm_breaker);
        await reply.react(shadow_caller);
        await reply.react(chill_howl);
        await reply.react(weeping);

        client.on('messageReactionAdd', async (reaction, user) => {
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();

            if (reaction.emoji.name == '⬅️'){
                avaEmbed.setFields({ name: "Offtank", value: user.id });
                await reply.edit({ embeds: [avaEmbed] });
            }
            console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
        });

我确实尝试了代码中的许多选项,但没有一个能让我找到答案。

lf3rwulv

lf3rwulv1#

我已经尝试了另一种方法,但过滤器仍然不工作,编辑嵌入式仍然窃听。

const offtankFilter = (reaction, user) => reaction.emoji === mace && user.id === interaction.user.id;
const ironrootFilter = (reaction, user) => reaction.emoji === mace && user.id === interaction.user.id;

const ironroots = reply.createReactionCollector(ironrootFilter, {time: 900000, dispose: false});
const offtanks = reply.createReactionCollector(offtankFilter, {time: 900000, dispose: false});
        
const nickname = `<@${interaction.user.id}>`;
      
offtanks.on("collect", r => {
  console.log("MASUK OFFTANK")
  avaEmbed.setFields({ name: "Offtank", value: `${mace} ${nickname}`});
  reply.edit({ embeds: [avaEmbed] });
  offtankcount += 1;
});
        
ironroots.on("collect", r => {
  console.log("MASUK IRON ROOT")
  avaEmbed.setFields({ name: "IronRoot", value: `${ironroot} ${nickname}`});
  reply.edit({ embeds: [avaEmbed] });
  ironrootcount += 1;
});

相关问题