当有人添加反应时,您如何编辑嵌入? DIscord.py
How do you edit an embed when someone adds a reaction? DIscord.py
我是 discord.py 的新手,对 python 有点经验。
我目前在添加反应时使用下面的代码来编辑嵌入。
@client.event
async def on_raw_reaction_add(payload):
if payload.emoji == "✅":
e = discord.Embed(
title="Tic Tac Toe",
description= "Play Tic Tac Toe",
color=0xFF5733)
e.add_field(name = "Choice", value = 'You have chosen Yes')
await payload.reaction.remove(payload.user)
await payload.message.edit(embed = e)
elif payload.emoji == "":
embed = ""
await payload.reaction.remove(payload.user)
await payload.message.edit(embed)
我的最终目标是能够在 Discord 中玩 TicTacToe。我目前正在尝试测试反应。我完全不知道为什么它不起作用。
使用 on_raw_reaction_add()
,您无法直接访问消息和反应,您必须检索它们:
from discord.utils import get
@client.event
async def on_raw_reaction_add(payload):
emoji = payload.emoji
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = get(message.reactions, emoji=emoji.name)
if emoji.name == "✅":
e = discord.Embed(
title="Tic Tac Toe",
description= "Play Tic Tac Toe",
color=0xFF5733)
e.add_field(name = "Choice", value = 'You have chosen Yes')
await reaction.remove(payload.member)
await message.edit(embed=e)
elif emoji.name == "":
await reaction.remove(payload.member)
await message.edit(embed=None)
我是 discord.py 的新手,对 python 有点经验。 我目前在添加反应时使用下面的代码来编辑嵌入。
@client.event
async def on_raw_reaction_add(payload):
if payload.emoji == "✅":
e = discord.Embed(
title="Tic Tac Toe",
description= "Play Tic Tac Toe",
color=0xFF5733)
e.add_field(name = "Choice", value = 'You have chosen Yes')
await payload.reaction.remove(payload.user)
await payload.message.edit(embed = e)
elif payload.emoji == "":
embed = ""
await payload.reaction.remove(payload.user)
await payload.message.edit(embed)
我的最终目标是能够在 Discord 中玩 TicTacToe。我目前正在尝试测试反应。我完全不知道为什么它不起作用。
使用 on_raw_reaction_add()
,您无法直接访问消息和反应,您必须检索它们:
from discord.utils import get
@client.event
async def on_raw_reaction_add(payload):
emoji = payload.emoji
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = get(message.reactions, emoji=emoji.name)
if emoji.name == "✅":
e = discord.Embed(
title="Tic Tac Toe",
description= "Play Tic Tac Toe",
color=0xFF5733)
e.add_field(name = "Choice", value = 'You have chosen Yes')
await reaction.remove(payload.member)
await message.edit(embed=e)
elif emoji.name == "":
await reaction.remove(payload.member)
await message.edit(embed=None)