T
T
TanderOFF2021-06-03 22:07:59
Python
TanderOFF, 2021-06-03 22:07:59

How to shuffle list after already use?

Hello ! I wanted to make a mini toy for a bot in the discord, so we added buttons, you can come up with something interesting.
More to the point:
I made a mini-tuple, and ran the random function to add this list to the buttons. But the result does not give anything, the console is empty.

koloda = ['one' , 'two', 'tho' , 'four' , 'inv']
    pop = random.shuffle(koloda)


    text = str(koloda)

    bad_chars = ["'"] 


    for i in bad_chars : 
        test_string = text.replace(i, '') 

    intext = str(test_string)


    test = random.randint(1, 1)
    lous = random.randint(1, 10)

    one = Button(style = ButtonStyle.green, label = ' 1', id='1')
    two = Button(style = ButtonStyle.green, label = ' 2', id='2')
    tho = Button(style = ButtonStyle.green, label = ' 3', id='3')
    four = Button(style = ButtonStyle.green, label = '4 ', id='4')
    inv = Button(style = ButtonStyle.green, label = ' 5', id='5')


    embed1 = discord.Embed(description="Testing", color=0x7900ff)


    message = await ctx.channel.send(embed=embed1 , components=['{}'.format(intext)])

upd: Needed
at the output:
message = await ctx.channel.send(embed=embed1 , components=)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-04
@TanderOFF

it filters the text by removing the
'
was: ['one' , 'two', 'tho' , 'four' , 'inv']
should be: [one , two, tho , four , inv]

It doesn't work like that. You cannot remove quotes and get a variable from a string.
I don't do discord, but there is no mention of the "components" parameter in the documentation. Well, let's assume he is. If you want to send these buttons in random order, then first you need to create them, then add them to the list, mix and send
one = Button(style = ButtonStyle.green, label = ' 1', id='1')
two = Button(style = ButtonStyle.green, label = ' 2', id='2')
tho = Button(style = ButtonStyle.green, label = ' 3', id='3')
four = Button(style = ButtonStyle.green, label = '4 ', id='4')
inv = Button(style = ButtonStyle.green, label = ' 5', id='5')

components = [one, two, tho, four, inv]
random.shuffle(components) # обратите внимание, что shuffle не возвращает новый список, а модифицирует оригинальный. 

message = await ctx.channel.send(embed=embed1 , components=components)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question