W
W
wz2021-03-21 18:52:52
Python
wz, 2021-03-21 18:52:52

Why is UnboundLocalError: local variable 'embed' referenced before assignment?

I wrote this code:
UnboundLocalError: local variable 'embed' referenced before assignment?

@bot.event
async def on_message(message):
    await bot.process_commands( message )
    splited = message.content.split(' ')
    if message.author.bot is False:
        if f'<@!822563111571423254>' in splited[0]:
            try:
                if splited[1] is None:
                    pass
                else:
                    pass
            except:
                embed = discord.Embed(title = f'Welcome!', timestamp = message.created_at, colour = discord.Colour.from_rgb(199, 182, 219),  description = f'''
        Hi {message.author.display_name}, my name **Osidium**!

        • My prefix - `o+`
        • Write the command 'o+help' to find out all my features.
        • Want to know a little about me? Write `o-about`.
        • Need help on the bot, or found a bug/error? Visit our server: [Join](https://discord.gg/tYr5xeSS79)''')
        await message.reply(embed=embed)


And got an error:

Traceback (most recent call last):

File "C:\Users\User\Downloads\Osidium\bot.py", line 188, in on_message
await message.reply(embed=embed)
UnboundLocalError: local variable 'embed ' referenced before assignment
Ignoring exception in on_message

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-03-21
@rensly

Read about scopes. The embed variable may not be declared at the time of use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question