I'm making a Discord bot in Python using discord.py. I'd like to set/modify a global variable from an async thread.
message = ""
@bot.command()
async def test(ctx, msg):
message = msg
However this doesn't work. How can I achieve something that does this?
As I said in the comment you have to use the keyword global in the functions wherever you are modifying the global variable. If you are just reading it in function than you don't need it.
message = ""
@bot.command()
async def test(ctx, msg):
global message
message = msg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With