如何将Discord机器人的Streaming状态修改为Idle并设置观看所在服务器
修改方法
你只需要调整on_ready事件末尾的bot.change_presence调用参数即可,两个核心改动点如下:
- 添加
status=discord.Status.idle参数,将机器人在线状态设置为Idle - 把原来的
discord.Streaming活动类型替换为discord.Activity,指定活动类型为watching,内容改为服务器数量相关展示文本
修改后的完整代码如下:
@bot.event async def on_ready(): print(f'Loged in as {bot.user}\n') cmds = filter(lambda e: e.endswith(".py"), os.listdir("commands")) print(f"Loading Commands") for cmd in cmds: bot.load_extension(f"commands.{cmd[:-3]}") print(f"Loaded {cmd}") await bot.change_presence( status=discord.Status.idle, activity=discord.Activity( type=discord.ActivityType.watching, name=f"{len(bot.guilds)} 个服务器" ) )
如果你需要保留原来的帮助命令提示,也可以把name参数改为f"{len(bot.guilds)} 个服务器 | {prefix}help",显示效果和你原来的Streaming状态的文本结构一致。
内容的提问来源于stack exchange,提问作者Galaxy_Shots
相关产品推荐
相关产品推荐

