我将如何创建一个命令来关闭Discord.py Bot?

时间:2019-02-06 19:53:25

标签: python bots discord shutdown repl.it

我已经重写了现有的Discord Bot,以便通过@client.command使用命令。

这是clear命令的示例,因此您可以了解该语言的工作原理。

@client.command()
async def echo(*args):
  output = ""
  for word in args:
    output += word
    output += " "
  await client.say(output)

我想创建2条命令。 它将-shutdown使该漫游器脱机且无响应的一种。 另一个将-restart阻止该漫游器,这意味着如果我更新代码,则运行重新启动命令,该漫游器将脱机,重新启动,然后返回。

我该怎么做?

因为我希望这些命令仅对我有用,所以我在下面留下了Discord用户ID,因此您可以将其包括在代码中。 432234718860148749

预先感谢, 高

2 个答案:

答案 0 :(得分:0)

https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.logout有您的答案

@client.command()
@commands.is_owner()
async def shutdown(ctx):
    await ctx.bot.logout()

但是,我还不知道如何通过命令重启机器人

答案 1 :(得分:0)

从最新版本(Discord.py 1.3.3)开始,尝试以下操作:

# Close the bot
@client.command(aliases=["quit"])
@commands.has_permissions(administrator=True)
async def close(ctx):
    await client.close()
    print("Bot Closed")  # This is optional, but it is there to tell you.
相关问题