【发布时间】:2021-07-19 09:24:36
【问题描述】:
这段代码:
await Bot.close()
用于注销Bot。
问题是我想写一个重启命令,像这样:
@Bot.command()
async def OFF(ctx, seconds:float):
await ctx.message.delete()
embed = Embed(title = "OFF", description = f"{ctx.message.author.mention} turned off me for {round(seconds)} seconds", color = Color.red())
await ctx.send(embed = embed)
await Bot.close()
await sleep(seconds)
await Bot.login(token)
embed = Embed(title = "Turned on", description = f"I came back after {round(seconds)}", color = Color.green())
await ctx.send(embed = embed)
问题是当 Bot 关闭时,必须重新启动 shell,否则程序在 {seconds}sec 后将无法继续运行。
如何创建一个重新启动 Bot 的命令?
提前致谢
【问题讨论】:
-
await sleep()已过时,您宁愿使用asyncio.sleep()。您是否看过其他也涉及重新启动机器人的帖子? StackOverflow 上有大量示例。 -
是的,我看了其他帖子,没有人回答我的问题。
-
(@Dominik,我在程序开始时做了“从时间导入睡眠”)
标签: python-3.x discord.py