これは本当に悪いことだとわかっていますが、それはうまく機能しています。だから私は実際にこれを書くために "より良い"方法を探しています。再帰的なランダム変数を書く方が良い
基本的には3スロットの画像が表示され、3スロットはランダム画像がSLOT_PATTERN
にリストされた画像を表示します。画像はedit_message
を使用して変更され、そこにあった以前の3つのスロット画像が編集され、指定されたリストのランダム画像に置き換えられます。
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')
あなたの投稿をvandalizeしないでください。質問を投稿したら、(CC-by-SAライセンスのもとで)大規模なスタックオーバーフローコミュニティにコンテンツのライセンスを取得しました。この投稿とアカウントとの関連付けを解除する場合は、[解約リクエストの適切なルートは何ですか]を参照してください(http://meta.stackoverflow.com/questions/323395/what-is-the-proper-route-解離要求のために)。 – FelixSFD