首页 > 解决方案 > Discord Python Bot:改变状态

问题描述

我知道,您可以通过以下方式更改您的机器人状态:

@bot.event
async def on_ready():
    await bot.change_presence(activity=.....(name="....."))

但是有没有一种简单的方法可以通过使用 asyncio 每隔 5 秒更改一次您的状态?感谢您的帮助:D

标签: pythondiscordbots

解决方案


基于Cool or Fool - SRS的命令,这里的答案非常有效:

@bot.event
async def on_ready():
    bot.loop.create_task(status_task()) # Create loop/task


async def status_task():
    while True:
        await bot.change_presence(activity=discord.Game("XXX"), status=discord.Status.online)
        await asyncio.sleep(ValueInSeconds) # Changes after x seconds
        await bot.change_presence(activity=discord.Game("XXX"), status=discord.Status.online)
        await asyncio.sleep(ValueInSeconds)
  • 您还可以将或设置watch为状态。listening tostreaming

更多你可以看看其他帖子


推荐阅读