将表情符号添加到嵌入消息
Adding an emoji to an embed message
我已经找了好几个小时了,但我没有找到任何关于为什么这对我不起作用的信息。
这是我的代码:
@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'
非常感谢任何帮助解决这个问题。
add_reaction
是Message
的方法,class不是Bot
。 Embed
不分classMessage
。要获取与 Embed
关联的 Message
对象,您需要存储 channel.send(embed=...)
的 return 值
message = await ticket_channel.send(embed=embed)
await message.add_reaction('\N{LOCK}')
我已经找了好几个小时了,但我没有找到任何关于为什么这对我不起作用的信息。 这是我的代码:
@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'
非常感谢任何帮助解决这个问题。
add_reaction
是Message
的方法,class不是Bot
。 Embed
不分classMessage
。要获取与 Embed
关联的 Message
对象,您需要存储 channel.send(embed=...)
message = await ticket_channel.send(embed=embed)
await message.add_reaction('\N{LOCK}')