Answer the question
In order to leave comments, you need to log in
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)])
Answer the question
In order to leave comments, you need to log in
it filters the text by removing the
'
was: ['one' , 'two', 'tho' , 'four' , 'inv']
should be: [one , two, tho , four , inv]
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 questionAsk a Question
731 491 924 answers to any question