【问题标题】:Discord bot going offline after a loopDiscord 机器人在循环后离线
【发布时间】: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 文件仍在运行,并且没有显示任何错误。有谁知道这是什么原因造成的?谢谢。

【问题讨论】:

标签: discord discord.py


【解决方案1】:

time.sleep(300) 阻止您的程序和连接超时。
使用await asyncio.sleep(300) insead。

【讨论】:

    猜你喜欢
    • 2020-08-12
    • 2021-08-17
    • 2021-11-08
    • 2021-10-06
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    相关资源
    最近更新 更多