My discord.py script gives me an unexpected error. It basically marks all the variables that I defined outside of async def on_message(): but used under that as "not defined".
Well, you could easily fix it by defining them under on_message() too. Which I tried.
But then, here's the problem: The variables would be set back to what you defined each time a message is sent, even if you did add, like a line saying change it to another value if this hapens. (e.g prefix, as you can see below in the code, I want to change the bot's prefix using a command called "changeprefix" and it works, HOWEVER when another message is sent with that prefix, it wouldn't recognize it; because the line defining the variable at the beginning ran again and it all got reset.
Is there a way else than just removing on_message() and using discord.ext.commands or something? I'm more familiar with the on-message() system, moreover I would change the whole script if I switch to it.
import discord
client = discord.Client()
token= "some nice token"
#defining here results in "UnboundLocalError: local variable 'prefix' referenced before assignment", in the first line using the variable defined here
@client.event
async def on_message(message):
#defining here results variables being refreshed each time a message is sent