[英]Background Task in random channels Discord.py
我正在嘗試讓我的后台任務使用random.choice()
在不同的通道中發送。 當我打開漫游器時,它將僅在一個隨機通道中發送,並且僅在該通道中發送。 有沒有一種方法可以在每次循環時發送不同的通道?
async def test_loop():
await client.wait_until_ready()
channels = ['550528972226', '5149003563352', '514900351233', '5799132312340']
channel = client.get_channel(random.choice(channels))
while not client.is_closed:
time = random.randint(1,5)+random.random()
monies = random.randint(100,250)
emojigrab = '💵'
emojimsg = await client.send_message(channel, emojigrab)
await client.add_reaction(emojimsg, "💰")
pay = await client.wait_for_reaction(emoji="💰", message=emojimsg, timeout=1800,
check=lambda reaction, user: user != client.user)
if pay:
await client.delete_message(emojimsg)
await client.send_message(channel, "{} secures the bag for ${:,}".format(pay.user.mention, monies))
add_dollars(pay.user, monies)
await asyncio.sleep(int(time))
當前, channel = client.get_channel(random.choice(channels))
在您的while循環之外,這意味着可變channel
永遠不會改變。 每次發送新消息時,將其移至while循環內即可進行更改。
async def test_loop():
await client.wait_until_ready()
channels = ['550528972226', '5149003563352', '514900351233', '5799132312340']
while not client.is_closed:
channel = client.get_channel(random.choice(channels))
time = random.randint(1,5)+random.random()
monies = random.randint(100,250)
emojigrab = '💵'
emojimsg = await client.send_message(channel, emojigrab)
await client.add_reaction(emojimsg, "💰")
pay = await client.wait_for_reaction(emoji="💰", message=emojimsg, timeout=1800,
check=lambda reaction, user: user != client.user)
if pay:
await client.delete_message(emojimsg)
await client.send_message(channel, "{} secures the bag for ${:,}".format(pay.user.mention, monies))
add_dollars(pay.user, monies)
await asyncio.sleep(int(time))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.