简体   繁体   中英

How can I keep track of a list in discord.py

Here's my code

amount = 0
list = []
#b is the client
@b.command()
async def hello(ctx):
if list == []:
    list.append("9")
    list.append("10")
    list.append("11")
    list.append("12")
else:
    amount += 1
    print(list[amount])

So there's a couple things I want to do, every time I run the command through discord I want it to add 1 to the amount, I also want the things that I appended in the command to be permanently added to the list as those values will change every time I run the command.

This is an example of what I want to print out:

After I run it once:

9

After I run it twice:

10

After I run three times:

11

something like this? (dis.py questions arent necessarily accessible to test immediately)

lst = []
#b is the client
@b.command()
async def hello(ctx):
    if not lst:
        lst.append(9)
    else:
        last = lst[-1]
        await ctx.send(last)
        lst.append(last + 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM