如何为我的 discord.py 机器人发出重启命令
How to make a restart command for my discord.py bot
到目前为止我得到的是:
def restart_program():
python = sys.executable
os.execl(python, python, * sys.argv)
@bot.command()
async def restart(ctx):
message = await ctx.send("Restarting... Allow up to 5 seconds")
restart_program()
这行得通,但是我想知道如何让它在重新启动后编辑“正在重新启动...允许最多 5 秒”消息以说“Bot 已备份”之类的内容。这可能吗?如果可以,我该怎么做?
我会使用 Client.logout()
和 Client.login()
来重启机器人而不是使用 os.execl
,但是如果你真的需要这样做,这里是你的方法每次启动都可以发消息:
@client.event
async def on_ready():
# First get the channel where the message should be sent
channel = discord.utils.get(client.get_all_channels(), name='general')
await channel.send("Bot is back up!")
到目前为止我得到的是:
def restart_program():
python = sys.executable
os.execl(python, python, * sys.argv)
@bot.command()
async def restart(ctx):
message = await ctx.send("Restarting... Allow up to 5 seconds")
restart_program()
这行得通,但是我想知道如何让它在重新启动后编辑“正在重新启动...允许最多 5 秒”消息以说“Bot 已备份”之类的内容。这可能吗?如果可以,我该怎么做?
我会使用 Client.logout()
和 Client.login()
来重启机器人而不是使用 os.execl
,但是如果你真的需要这样做,这里是你的方法每次启动都可以发消息:
@client.event
async def on_ready():
# First get the channel where the message should be sent
channel = discord.utils.get(client.get_all_channels(), name='general')
await channel.send("Bot is back up!")