如何让特定角色能够在 Nextcord 中使用斜杠命令?

How do you make a specific role able to use a slash command in Nextcord?

如何让特定角色能够在 Nextcord 中使用斜杠命令?

我发现在 Nextcord 中使用斜杠命令时使用 @command.has_permissions(manage_messages=True) 不起作用,例如:

@bot.slash_command(description="Hello")
@command.has_permissions(manage_messages=True)
async def hi(interaction : Interaction):
    await interaction.send("Hello!")

我已经在没有适当权限的情况下使用 alt 帐户对此进行了测试,该命令仍然有效。

这是 Nextcord 的错误还是有其他方法可以使用斜杠命令来做到这一点?

对于斜杠命令,它在 application_checks 中。好像是。

from nextcord.ext import application_checks

@bot.slash_command()
@application_checks.has_permissions(manage_messages=True)
async def testperms(interaction: Interaction):
    await interaction.response.send_message('You can manage messages.')

Reference