【问题标题】:How to restart a discord.py bot using commands?如何使用命令重新启动 discord.py 机器人?
【发布时间】:2020-12-12 11:35:52
【问题描述】:

我在 discord.py 中有一个不和谐机器人,并且想使用命令发出重启命令。 我看到了:

await login(token, *, bot=True)

在文档上,但这不起作用,它会将“登录”标记为未知。 我不知道该怎么办,因为其他解决方案是使用客户端而不是命令。

这是我试过的代码:

@bot.command(pass_context=True)
@commands.is_owner()
async def restart(ctx):
    await ctx.send("Restarting Bot <a:loading_colored:744984714624106528>")
    login(token, *, bot=True)

我定义了 token 变量。 我必须改变什么? 请帮帮我。

【问题讨论】:

  • 我不确定,但您尝试过this 吗?也许您可以注销然后再次登录。

标签: python command discord.py restart


【解决方案1】:

您可以使用discord.ext.commands.Bot.logoutdiscord.ext.commands.Bot.login 重新启动您的机器人,这是一个示例:

from discord.ext import commands

@client.command()
@commands.is_owner()
async def restartBot(ctx):
    await ctx.bot.logout()
    await login("your_token", bot=True)

【讨论】:

  • 这不会阻止机器人吗?
  • 它强调了login。我必须导入任何东西吗?
  • 导入不和谐。
  • 我认为您不需要其他任何东西,您是否遇到任何错误?
  • 我的机器人在关闭后没有启动备份
猜你喜欢
  • 2021-01-07
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
  • 2022-06-28
  • 2021-01-01
  • 2021-10-06
  • 2022-01-10
  • 1970-01-01
相关资源
最近更新 更多