-1

I want it to show 7 first, then 4, 1 when entering the command, but it always shows 7, 7, 7

@client.command()
async def test(ctx):
    bint = 3
    money1 = 10
    if money1 >= 3:
        money1 = money1 - bint
        await ctx.send(money1)
rusyator
  • 1
  • 1
  • It's hard guessing what you want. Do you want this `money1` variable to be consistent across restarts (see the answer by @Hajime), or just throughout the bot? Is it meant to be global to the bot or unique to guilds/users/etc? – Eric Jin Jun 05 '22 at 20:34
  • Does this answer your question? [What is the Python equivalent of static variables inside a function?](https://stackoverflow.com/questions/279561/what-is-the-python-equivalent-of-static-variables-inside-a-function) – TheFungusAmongUs Jun 06 '22 at 02:05

1 Answers1

0

You can use a global variable for that or store the variable somewhere else. What I usually do is make a config.py file in the base directory and then put variable there like

config.py

money1 = 10

in you code

import config

bint = 3
if config.money1 >= 3:
    config.money1 - bint
    await ctx.send(config.money1)

You can as well use your discord client (not recommend) like this:

try:
    client.money1
except:
    client.money1 = 10
...
Hajime
  • 21
  • 3