python - discord.embed 更新与角色反应
问题描述
我正在尝试用反应更新 discord.embed:
@bot.command()
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")
我创建了一个嵌入了一些默认信息的不和谐,并添加了我想要使用的反应,其想法是当有人对选择反应之一做出反应时,用户的名称被添加到该字段中。
(我实际上有 4 个命令使用相同的“模板”并具有相同的反应,我希望它们都单独工作)
解决方案
您需要为此使用wait_for
。
也on_raw_reaction_add
只需要一个参数payload
,我相信你正在尝试使用on_reaction_add
如果您只想考虑添加的第一个反应,请删除 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")
推荐阅读
- dsl - 为什么我们在空手道报告中使用 karate.abort() 将“跳过步骤”视为“失败的步骤”?
- solr - 使用 tika 索引某些文档后如何从 solr 关键字搜索中获取段落结果?
- python - 如何在 Python 包中支持备用依赖项?
- javascript - 我在将值附加到数组中时遇到问题
- ibm-watson - 如何让麦克风直接流式传输到 watson speechToText 服务
- javascript - React 只重新渲染修改过的 contenteditable 一次
- elasticsearch - ElasticSearch Kibana 监控数据开始丢失数据
- php - 如何在 TCPDF 中编码 UTF-8
- c# - 无法让我的相机正确限制其旋转
- c - ip头的布局和网络编程