首页 > 解决方案 > 当用户对 discord.py rewrite 中的消息做出反应时,如何进行嵌入更改?

问题描述

标签: pythonpython-3.xdiscorddiscord.pydiscord.py-rewrite

解决方案


我也在想同样的事情。我现在可以接受用户的反应,但不能清除它们,所以他们必须按两次(一次清除然后做出反应),而且所有嵌入在发送时进行编辑这是我的代码供参考:

def check(reaction, user):
        return user == author and str(reaction.emoji) in ["➡","⬅"]

    help_list=[help_embed,server_embed,greet_embed,fun_embed,music_embed,utility_embed]
    count=0
    help_msg=await ctx.send(embed=help_list[count])
    await help_msg.add_reaction("⬅")
    await help_msg.add_reaction("➡")
    
    while True:
        reaction, user = await self.bot.wait_for('reaction_add',check=check)
        print(str(reaction))
        if str(reaction.emoji) == "➡":
            count+=1
            if count>len(help_list)-1:
                count=0
            await help_msg.edit(embed=help_list[count])
            await help_msg.add_reaction("⬅")
            await help_msg.add_reaction("➡")
    
        elif str(reaction.emoji) == "⬅":
            count-=1
            if count<0:
                count=len(help_list)-1
            await help_msg.edit(embed=help_list[count])
            await help_msg.add_reaction("⬅&quot;)
            await help_msg.add_reaction("➡&quot;)

注意:help_list 只是嵌入列表。

谢谢!


推荐阅读