Python 向嵌入消息添加表情符号
我已经找了好几个小时了,但我没有发现为什么这对我不起作用。 这是我的密码:Python 向嵌入消息添加表情符号,python,discord.py-rewrite,Python,Discord.py Rewrite,我已经找了好几个小时了,但我没有发现为什么这对我不起作用。 这是我的密码: @bot.command() async def ticket(ctx): name = "tickets" category = discord.utils.get(ctx.guild.categories, name=name) guild = ctx.message.guild ticket_id = randint(0, 100) ticket_channel = await guild.cr
@bot.command()
async def ticket(ctx):
name = "tickets"
category = discord.utils.get(ctx.guild.categories, name=name)
guild = ctx.message.guild
ticket_id = randint(0, 100)
ticket_channel = await guild.create_text_channel(f"ticket-0{ticket_id}", category=category)
embed = discord.Embed(title="Tickets", description="Support will be with you shortly.\nTo close this ticket, react with :lock:.")
await ticket_channel.send(embed=embed)
await bot.add_reaction(embed, emoji=":lock:")
while True:
await bot.wait_for_reaction(emoji="\N{LOCK}", message=embed)
await bot.delete_channel(ticket_channel)
这是我得到的错误:
Ignoring exception in command ticket:
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/ext/commands/core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 40, in ticket
await bot.add_reaction(embed, emoji=":lock:")
AttributeError: 'Bot' object has no attribute 'add_reaction'
非常感谢您为解决此问题提供的任何帮助。
添加反应
是消息
类的一种方法,而不是机器人
<代码>嵌入不将消息子类化
。要获取与Embed
关联的消息
对象,您需要存储channel.send的返回值(Embed=…)
message=wait ticket\u channel.send(嵌入=嵌入)
等待消息。添加\u反应('\N{LOCK}')
add\u reaction
是Message
类的一种方法,而不是Bot
<代码>嵌入不将消息子类化
。要获取与Embed
关联的Message
对象,您需要存储channel.send的返回值(Embed=…)
哦,我真的很笨。我忘了。我试图将反应添加到实际嵌入中,而不是消息中。