【发布时间】:2019-04-17 20:29:24
【问题描述】:
我想让我的机器人在一段时间后出现变化。 (在这种情况下为 5 分钟)
@client.event
async def on_ready():
while True:
presence = randint(1, 5)
if presence == 1:
await client.change_presence(game=discord.Game(name='with commands', type=1))
elif presence == 2:
await client.change_presence(game=discord.Game(name='you', type=3))
elif presence == 3:
await client.change_presence(game=discord.Game(name='and watching', type=2))
elif presence == 4:
await client.change_presence(game=discord.Game(name='Youtube Videos', type=3))
elif presence == 5:
await client.change_presence(game=discord.Game(name='like a boss', type=1))
time.sleep(300)
问题是,在 300 秒后,我的机器人在不和谐的情况下离线,而 python 文件仍在运行,并且没有显示任何错误。有谁知道这是什么原因造成的?谢谢。
【问题讨论】:
-
使用
await asyncio.sleep而不是time.sleep。见What does blocking mean?
标签: discord discord.py