【发布时间】:2021-10-12 04:51:13
【问题描述】:
我是 Python 新手,尝试为我的不和谐机器人添加反应角色,但我的机器人成功发送消息,但不要在消息中添加表情符号。
@client.event
async def on_message(message):
if message.content.lower().startswith("!lol"):
embed1 = discord.Embed(
title="Escolha seu Elo!",
color=COR,
description="- Ferro = ????\n"
"- Bronze = ????\n"
"- Prata = ???? \n"
"- Ouro = ????\n"
"- Platina = ????\n"
"- Diamante = ✋\n"
"- Mestre = ????\n"
"- Grã-Mestre = ✊\n"
"- Desafiante = ????\n",)
botmsg = await message.channel.send(embed=embed1)
await ctx.message.add_reaction(botmsg, "????")
await ctx.message.add_reaction(botmsg, "????")
await ctx.message.add_reaction(botmsg, "????")
await ctx.message.add_reaction(botmsg, "????")
await ctx.message.add_reaction(botmsg, "????")
await ctx.message.add_reaction(botmsg, "✋")
await ctx.message.add_reaction(botmsg, "????")
await ctx.message.add_reaction(botmsg, "✊")
await ctx.message.add_reaction(botmsg, "????")
global msg_id
msg_id = botmsg.id
global msg_user
msg_user = message.author
这是我得到的错误我已经尝试了很多解决方法我找不到任何可以解决这个问题的方法
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 55, in on_message
botmsg = await message.channel.send(embed=embed1)
UnboundLocalError: local variable 'embed1' referenced before assignment
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 57, in on_message
await ctx.message.add_reaction(botmsg, "????")
NameError: name 'ctx' is not defined
我也试过用
emoji = client.get_emoji(310177266011340803)
await message.add_reaction(emoji)
但这也行不通
upd:这些表情符号是示例,我想同时使用 unicode 表情符号和自定义表情符号
【问题讨论】:
标签: python discord.py bots roles