我已经制作了带有反应的超级简单的票务系统,但它不起作用:c。这是我的代码:
@client.event
async def on_reaction_add(reaction, user):
if 'React with ? to create a ticket' in reaction.message.embeds and reaction.emoji == '?':
role = discord.utils.get(user.guild.roles, name="@everyone")
chan = await user.guild.create_text_channel(name=f'ticket - {user}')
await chan.set_permissions(role, send_messages=False, read_messages=False, add_reactions=False, embed_links=False, attach_files=False, read_message_history=False, external_emojis=False)
await chan.set_permissions(user, send_messages=True, read_messages=True, add_reactions=True, embed_links=True, attach_files=True, read_message_history=True, external_emojis=True)
embed = discord.Embed(
title="Ticket",
description="React with ? to close a ticket",
color=0
)
embed.set_footer(text="Ticket system")
msg = await chan.send(embed=embed)
await msg.add_reaction("?")
if 'React with ? to close a ticket' in reaction.message.content and reaction.emoji == '?':
await reaction.channel.delete()
@client.command()
@commands.has_permissions(administrator=True)
async def newticket(ctx, channel: discord.TextChannel = None):
if channel==None:
await ctx.channel.purge(limit=1)
embed = discord.Embed(
title="Ticket",
description="React with ? to create a ticket",
color=0
)
embed.set_footer(text="Ticket system")
msg = await ctx.send(embed=embed)
await msg.add_reaction("?")
else:
await ctx.channel.purge(limit=1)
embed = discord.Embed(
title="Ticket",
description="React with ? to create a ticket",
color=0
)
embed.set_footer(text="Ticket system")
msg = await channel.send(embed=embed)
await msg.add_reaction("?")
我没有任何错误。但是,当我对消息做出反应并嵌入消息时,什么也没有发生,所以我认为错误在这一行:if 'React with ? to create a ticket' in reaction.message.embeds and reaction.emoji == '?':
如您所见,我尝试制作脚本,如果嵌入的内容是“与 ? 反应以创建票证”,则该脚本将创建一个频道'(在描述中)以及如果有人对?做出反应。
答案 0 :(得分:1)
reaction.message.embeds
返回消息的嵌入列表。这意味着您无法从此访问嵌入的描述内容。您必须获得 discord.Embed
实例,然后才能使用 .description
类的 discord.Embed
属性。它会返回嵌入的描述内容。
@client.event
async def on_reaction_add(reaction, user):
if 'React with ? to create a ticket' in reaction.message.embeds[0].description and reaction.emoji == '?' and not user.bot:
...