python - Discord Python Bot:改变状态
问题描述
我知道,您可以通过以下方式更改您的机器人状态:
@bot.event
async def on_ready():
await bot.change_presence(activity=.....(name="....."))
但是有没有一种简单的方法可以通过使用 asyncio 每隔 5 秒更改一次您的状态?感谢您的帮助:D
解决方案
基于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 to
streaming
更多你可以看看其他帖子
推荐阅读
- angular - 带有方法的对象上的打字稿spad运算符
- rest - 如何从 REST API 中的 Firestore 文档中查询单个字段?
- jquery - jQuery Multislect 框序列化搜索框,而不是实际选择
- ios - UIButton 在点击时更改背景(以编程方式)
- outlook - Outlook 加载项在读取模式下不工作
- jquery - 从上到下然后向左绘制边框
- android - RecyclerView 不调用 OnCreateViewHolder、OnBindViewHolder、GetItemCount()
- r - 如何使用集成学习方法为时间序列数据构建数据框
- javascript - 如何以编程方式在 svg 路径中构建曲线?
- php - 一定时间后限制访问节点