我正在开发一个 Discord 机器人,并尝试创建一个可点击的斜杠命令链接。但是,我无法找到斜杠命令的 ID
command = self.bot.tree.get_command("rank")
await message.reply(f"To view your rank, please click here </rank:{command.id}> 🔍")
不幸的是,我发现
command
没有 id
属性,这导致生成可点击链接时出现问题。
get_command()
函数返回bot.command
而不是bot.tree.command
。
为此,您需要 fetch_commands()
函数。
这是例子:
@bot.command()
async def commandid(ctx,name):
commands = await bot.tree.fetch_commands()
for cmd in commands:
if cmd.name == name:
await ctx.send(cmd.id)