Discord bot在循环后脱机

Discord bot在循环后脱机,discord,discord.py,Discord,Discord.py,我想让我的机器人在一段时间后出现变化。(本例中为5分钟) 问题是,在300秒后,我的bot在discord上离线,而python文件仍在运行,并且没有显示任何错误。谁知道这是什么原因?谢谢。时间。睡眠(300)阻止您的程序和连接超时。 使用wait asyncio.sleep(300)insead.使用wait asyncio.sleep而不是time.sleep。看见 @client.event async def on_ready(): while True: pre

我想让我的机器人在一段时间后出现变化。(本例中为5分钟)

问题是,在300秒后,我的bot在discord上离线,而python文件仍在运行,并且没有显示任何错误。谁知道这是什么原因?谢谢。

时间。睡眠(300)
阻止您的程序和连接超时。

使用
wait asyncio.sleep(300)
insead.

使用
wait asyncio.sleep
而不是
time.sleep
。看见
@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)