简体   繁体   English

Discord 嵌入更新与角色反应 | Python

[英]Discord embed update with role reaction | python

i'm trying to update a discord.embed with reaction :我正在尝试使用反应更新 discord.embed :

async def expedition(ctx, expe, date, heure):
    embed=discord.Embed(title="Expedition", description= expe + "\n" + date + " : " + heure + "\nFor " + ctx.message.author.mention, color=0xFF5733)
    embed.add_field(name="tank", value="1 slots", inline=True)
    embed.add_field(name="heal", value="1 slots", inline=True)
    embed.add_field(name="dps", value="3 slots", inline=True)
    msg = await ctx.send(embed=embed)
    await msg.add_reaction('\N{SHIELD}')
    await msg.add_reaction('🧑‍⚕️')
    await msg.add_reaction('\N{CROSSED SWORDS}')
    await msg.add_reaction('❌')

    @client.event
    async def on_raw_reaction_add(reaction,user):
        if reaction.emoji == '\N{SHIELD}':
            embed.set_field_at(0,name="tank",value=user.mention)
            print("test 1")
        if reaction.emoji == '🧑‍⚕️':
            embed.set_field_at(1,name="heal",value=user)
            print("2 test")
        if reaction.emoji == '\N{CROSSED SWORDS}':
            embed.set_field_at(2,name="dps",value=user)
            print("D la réponse D")

I create a discord embed with some default information, and add the reaction I want to use, the idea is that when someone react with one of the select reaction, the name of the user is added to the field.我创建了一个嵌入了一些默认信息的不和谐,并添加了我想要使用的反应,这个想法是当有人对选择的反应之一做出反应时,用户的名字被添加到字段中。

( I actually have 4 commands using the same "template" with the same reaction, and I want them all to work individually ) (我实际上有 4 个命令使用相同的“模板”并具有相同的反应,我希望它们都能单独工作)

If anyone know a way to do so :D如果有人知道这样做的方法:D

Thanks for all :)谢谢大家:)

You need to use wait_for for this.为此,您需要使用wait_for

Also on_raw_reaction_add takes only one argument that is payload , I believe you are trying to use on_reaction_add此外on_raw_reaction_add只接受一个参数,即payload ,我相信您正在尝试使用on_reaction_add

Remove the while loop if you wish to consider only the first reaction that is added如果您只想考虑添加的第一个反应,请删除 while 循环

async def expedition(ctx, expe, date, heure):
    embed=discord.Embed(title="Expedition", description= expe + "\n" + date + " : " + heure + "\nFor " + ctx.message.author.mention, color=0xFF5733)
    embed.add_field(name="tank", value="1 slots", inline=True)
    embed.add_field(name="heal", value="1 slots", inline=True)
    embed.add_field(name="dps", value="3 slots", inline=True)
    msg = await ctx.send(embed=embed)
    await msg.add_reaction('\N{SHIELD}')
    await msg.add_reaction('🧑‍⚕️')
    await msg.add_reaction('\N{CROSSED SWORDS}')
    await msg.add_reaction('❌')

    while True:
        reaction, user = await client.wait_for("reaction_add", check=lambda reaction, user: reaction.message.id == msg.id)
        if reaction.emoji == '\N{SHIELD}':
            embed.set_field_at(0,name="tank",value=user.mention)
            print("test 1")
        if reaction.emoji == '🧑‍⚕️':
            embed.set_field_at(1,name="heal",value=user)
            print("2 test")
        if reaction.emoji == '\N{CROSSED SWORDS}':
            embed.set_field_at(2,name="dps",value=user)
            print("D la réponse D")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM