Discord Bot,如何修复 UnboundLocalError:分配前引用的局部变量“embed_2”?

时间:2021-05-25 09:32:06

标签: python discord bots

我是这个领域的新手。我正在用 Python 编码。我制作了嵌入消息(Discord) - 一切都很好。但是,当我创建另一条 Embed 消息时,它显示“UnboundLocalError: local variable 'embed_2' referenced before assignment”错误。请帮我解决这个问题,我将不胜感激!

if message.content.startswith("_help"):
    embed = discord.Embed(

        title = "Commands",
        description = "Use this column, so I can help you with my commands out!",
        colour = discord.Colour.green()
    )

    embed.add_field(name="Prefix", value="( _ ) Underscore", inline=False)
    embed.add_field(name="Hey!", value="Wha?", inline=True)

await message.channel.send("As you ordered!", embed=embed)



if message.content.startswith("_apf"):
    embed_2 = discord.Embed(
        title = "Additional commands",
        description="Commands, but more advanced",
        colour=discord.Colour.orange()
    )

    embed_2.add_field(name="_howdy", value="Heya!", inline=True)
    embed_2.add_field(name="_how are u", value="Pretty noice", inline=True)

await message.channel.send("Here you go", embed=embed_2)

在那之后,我一直得到这个!

UnboundLocalError: local variable 'embed_2' referenced before assignment

顺便说一句,使命令“全局”无法正常工作,因为在该机器人开始响应每条消息之后(即使它不在代码中)

谢谢!

0 个答案:

没有答案