Bot 不会在消息中添加表情符号

Bot don't add emoji to message

我是 Python 的新手,我尝试为我的 discord 机器人添加反应角色,但我的机器人成功发送了消息,但没有在消息中添加表情符号。

@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)

但这也行不通

更新:这些表情符号是示例,我想同时使用 unicode 表情符号和自定义表情符号

试试这个:

@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 botmsg.add_reaction("")
    await botmsg.add_reaction("")
    await botmsg.add_reaction("")
    await botmsg.add_reaction("")
    await botmsg.add_reaction("")
    await botmsg.add_reaction("✋")
    await botmsg.add_reaction("")
    await botmsg.add_reaction("✊")
    await botmsg.add_reaction("")

    global msg_id
    msg_id = botmsg.id

    global msg_user
    msg_user = message.author

调用 on_message 时未传递上下文参数。您可以使用 message.add_reaction().
而不是 ctx.message.add_reaction() 编辑:哦,我明白你的全部问题,现在脚本应该对你的机器人的消息做出反应。