Je sais que c'est vraiment mauvais, mais cela fonctionne et c'était le seul moyen avec mes connaissances actuelles pour terminer le travail. Je suis donc à la recherche d'un "meilleur" moyen d'écrire ceci.Meilleure façon d'écrire des variables aléatoires récursives
Fondamentalement, il montre 3 emplacements d'images et ces 3 emplacements changent d'images avec les images aléatoires énumérées dans SLOT_PATTERN
. Les images changent en utilisant edit_message
pour éditer les images précédentes à 3 emplacements qui étaient là, en les remplaçant par des images aléatoires de la liste donnée.
import discord, asyncio, time, random
client = discord.Client()
@client.event
async def on_message(message):
SLOT_PATTERN = [':four_leaf_clover:', ':moneybag:', ':cherries:', ':lemon:', ':grapes:', ':poop:', ':bell:', ':chocolate_bar:', ':watermelon:', ':six:', ':seven:', ':crown:']
wheel_pick1 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick2 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick3 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick4 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick5 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick6 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick7 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick8 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick9 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick10 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick11 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick12 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick13 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick14 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick15 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick16 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick17 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick18 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick19 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick20 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick21 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick22 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick23 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick24 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick25 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick26 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick27 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick28 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick29 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
wheel_pick30 = SLOT_PATTERN[random.randint(0, len(SLOT_PATTERN) - 1)]
if message.content.lower().startswith("!slots"):
slot1 = await client.send_message(message.channel, '%s %s %s' % (wheel_pick1, wheel_pick2, wheel_pick3))
time.sleep(0.25)
slot2 = await client.edit_message(slot1, '%s %s %s' % (wheel_pick4, wheel_pick5, wheel_pick6))
time.sleep(0.25)
slot3 = await client.edit_message(slot2, '%s %s %s' % (wheel_pick7, wheel_pick8, wheel_pick9))
time.sleep(0.50)
slot4 = await client.edit_message(slot3, '%s %s %s' % (wheel_pick10, wheel_pick11, wheel_pick12))
time.sleep(0.50)
slot5 = await client.edit_message(slot4, '%s %s %s' % (wheel_pick13, wheel_pick14, wheel_pick15))
time.sleep(0.75)
slot6 = await client.edit_message(slot5, '%s %s %s' % (wheel_pick16, wheel_pick17, wheel_pick18))
time.sleep(0.75)
slot7 = await client.edit_message(slot6, '%s %s %s' % (wheel_pick19, wheel_pick20, wheel_pick21))
time.sleep(1)
slot8 = await client.edit_message(slot7, '%s %s %s' % (wheel_pick22, wheel_pick23, wheel_pick24))
time.sleep(1)
slot9 = await client.edit_message(slot8, '%s %s %s' % (wheel_pick25, wheel_pick26, wheel_pick27))
time.sleep(1)
await client.edit_message(slot9, '%s %s %s' % (wheel_pick28, wheel_pick29, wheel_pick30))
client.run('clienttokenhere')
S'il vous plaît ne pas vandaliser vos messages. Une fois que vous avez publié une question, vous avez concédé sous licence le contenu à la communauté Stack Overflow en général (sous la licence CC-by-SA). Si vous souhaitez dissocier ce message de votre compte, voir [Quel est le chemin approprié pour une demande de dissociation?] (Http://meta.stackoverflow.com/questions/323395/what-is-the-proper-route- for-a-dissociation-request). – FelixSFD