samedi 21 juillet 2018

Random function doesn't work within discord bot

I wanted to get a lsit containing an amount of randomly generated digits between 0-9, and I used:

for a in range(2**power):
    tree[levels-1].append(random.randint(0,9))

which outputs something like: [0, 3, 2, 4, 3, 9, 4, 8] When used in isolation in another program.

However when I tried to do this within a function within a command in a discord bot:

First command:

@client.command()
async def game():
    tree = await maketree(4)

Function within command:

def maketree(levels):
   for a in range(2**power):
       tree[levels-1].append(random.randint(0,9))

I get the error: 'Command' object has no attribute 'randint'




Aucun commentaire:

Enregistrer un commentaire