Discord.py 重写所有命令的收集列表
Discord.py Rewrite gathering list of all commands
我正在尝试获取我的 Discord 机器人中重写的所有命令的列表。我正在使用 Python 3.6 编写此
我尝试通过执行来打印命令列表
print(bot.commands)
这只为我提供了以下 return:
{<discord.ext.commands.core.Command object at 0x00000209EE6AD4E0>, <discord.ext.commands.core.Command object at 0x00000209EE6AD470>}
我希望通常的输出是 clear()
,因为这是迄今为止我在机器人中编写的唯一命令,该命令按预期工作。但它只打印上面的
我想你正在寻找这样的东西。
@bot.command(name="help", description="Returns all commands available")
async def help(ctx):
helptext = "```"
for command in self.bot.commands:
helptext+=f"{command}\n"
helptext+="```"
await ctx.send(helptext)
这些是您的机器人拥有的 Command
个对象。有两个的原因是因为您的机器人有一个内置的 help
命令,它可以完全满足您的需求。如果您的 clear
命令是
@bot.command()
async def clear(ctx):
"A command for clearing stuff"
pass
然后 运行 !help
会给你输出
No Category:
help Shows this message.
clear A command for clearing stuff
Type !help command for more info on a command.
You can also type !help category for more info on a category.
我真的来晚了,但我想分享这个。
添加到 akiva 和 damaredayo 的响应中,这是一个基本命令,它将获取 cogs 和 主文件中的所有命令。
@bot.command()
async def commandcount(ctx):
counter = 0
for command in bot.commands:
counter += 1
await ctx.send(f"There are `{counter}` commands!")
@commands.command(help = "Blah")
async def l1(self,ctx):
commands = [c.name for c in self.client.commands]
print(commands)
你得到的是命令对象,所以如果你想要命令的名称,你可以得到名称 Command.name
。
参考:https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Command.name
我正在尝试获取我的 Discord 机器人中重写的所有命令的列表。我正在使用 Python 3.6 编写此
我尝试通过执行来打印命令列表
print(bot.commands)
这只为我提供了以下 return:
{<discord.ext.commands.core.Command object at 0x00000209EE6AD4E0>, <discord.ext.commands.core.Command object at 0x00000209EE6AD470>}
我希望通常的输出是 clear()
,因为这是迄今为止我在机器人中编写的唯一命令,该命令按预期工作。但它只打印上面的
我想你正在寻找这样的东西。
@bot.command(name="help", description="Returns all commands available")
async def help(ctx):
helptext = "```"
for command in self.bot.commands:
helptext+=f"{command}\n"
helptext+="```"
await ctx.send(helptext)
这些是您的机器人拥有的 Command
个对象。有两个的原因是因为您的机器人有一个内置的 help
命令,它可以完全满足您的需求。如果您的 clear
命令是
@bot.command()
async def clear(ctx):
"A command for clearing stuff"
pass
然后 运行 !help
会给你输出
No Category: help Shows this message. clear A command for clearing stuff Type !help command for more info on a command. You can also type !help category for more info on a category.
我真的来晚了,但我想分享这个。
添加到 akiva 和 damaredayo 的响应中,这是一个基本命令,它将获取 cogs 和 主文件中的所有命令。
@bot.command()
async def commandcount(ctx):
counter = 0
for command in bot.commands:
counter += 1
await ctx.send(f"There are `{counter}` commands!")
@commands.command(help = "Blah")
async def l1(self,ctx):
commands = [c.name for c in self.client.commands]
print(commands)
你得到的是命令对象,所以如果你想要命令的名称,你可以得到名称 Command.name
。
参考:https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Command.name