【发布时间】:2020-12-02 13:50:33
【问题描述】:
我正在尝试编写一个每 60 秒更改一次机器人状态的代码,但我无法让它工作。我搜索了如何制作它,但似乎没有人尝试过这样做。或者至少我找不到类似的东西。
我尝试了这段代码,但它不起作用,机器人永远不会更改为第二状态 =/
# Bot joins server/auto msg
@bot.event
async def on_ready():
log_channel = bot.get_channel(log_id)
join_embed = discord.Embed(title='Rosy is back online', color=0xd3d3d3)
join_embed.set_author(name='')
await log_channel.send(embed=join_embed)
while True:
await bot.change_presence(activity=discord.Game(name='?help if you are wondering anything')) # First status
time.sleep(60) # Wait 60 seconds
await bot.change_presence(activity=discord.Game(name='TEST!')) # Show second status then repeat
我还希望第二个状态显示不和谐服务器中的总成员...
感谢您的帮助!
编辑:
@tasks.loop(seconds=10.0)
async def my_background_task():
"""Will loop every 60 seconds and change the bots presence"""
await bot.change_presence(activity=discord.Game(name='?help if you are wondering anything'))
await bot.change_presence(activity=discord.Game(name='TEST!'))
@bot.event
async def on_ready():
# Waiting until the bot is ready
await bot.wait_until_ready()
# Starting the loop
my_background_task.start()
【问题讨论】:
标签: bots discord.py status