Reputation: 37
@bot.command()
async def blackjack(ctx):
cards = "♣️3"
@bot.event
async def on_message(msg):
globals cards
print(cards)
I'm making a blackjack command in discord.py but ran into a problem where the variable "cards" is not defined (because it isn't a local variable) I'm not sure how to fix this. I tried including "globals cards" but it still didn't work.
Upvotes: 1
Views: 575
Reputation: 468
It can't access the variable because you define it in a separate method. If you define the variable outside of both methods, then all of your methods may access and change the variable freely.
Code
cards = "♣️3"
@bot.command()
async def blackjack(ctx):
#code here
pass
@bot.event
async def on_message(msg):
print(cards)
Upvotes: 3