'Replit Discord Unbound Local Errors for no reason
I have made a discord bot using Replit and all of a sudden I get an UnboundLocalError. It has only just started doing it after working many times previously without changing anything. Here is my code:
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
This as mentioned should work like a charm; however, I start getting this random error which I can't seem to fix:
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 553, in on_message
if message.author == client.user:
UnboundLocalError: local variable 'client' referenced before assignment
This is really annoying me as it was just working perfectly and now it's not. I'm using Replit and have tried everything to resolve it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
