So, I´m making a discord.py bot and i want to create a /daily command. But I need to use a variable inside a function declared outside of the function. Here's my code so far:
global d
d = 0
@tree.command(name = "daily", description = "Daily sallary.")
async def daily(interaction: discord.Interaction):
if d == 0:
await interaction.response.send_message("Yes")
d = 1
await asyncio.sleep(86400)
d = 0
else:
await interaction.response.send_message("No")
The d variable is not working inside of the function and it throws out this error:
UnboundLocalError: cannot access local variable 'd' where it is not associated with a value
Anyone has an idea of how to do this?
I have tried this:
global d
d = 0
@tree.command(name = "daily", description = "Daily sallary.")
async def daily(interaction: discord.Interaction, **d=d**):
if d == 0:
await interaction.response.send_message("Yes")
d = 1
await asyncio.sleep(86400)
d = 0
else:
await interaction.response.send_message("No")
but.... It doesn't work and again there's an error: TypeError: parameter 'd' is missing a type annotation in callback 'daily'