简体   繁体   English

discord.CommandPermission 究竟是如何工作的?

[英]How exactly does discord.CommandPermission work?

I try to gray out some slash commands that only someone with the right permissions can use.我尝试将一些只有具有正确权限的人才能使用的斜杠命令变灰。 I found out that you can gray them out for everyone if you set default_permission = False .我发现如果您设置default_permission = False ,您可以为每个人将它们灰显。 Then I found out that theres a permissions attribute that you can provide.然后我发现您可以提供一个权限属性。 But I just can't get it working.但我就是无法让它工作。 I tried using it like this permissions = [discord.CommandPermission(id=8589934592, type=3)] But with this the command is disabled for everyone.我试过像这样使用它permissions = [discord.CommandPermission(id=8589934592, type=3)]但是有了这个命令对每个人都被禁用了。 My complete command looks like this:我的完整命令如下所示:

@slash_command(name='testcommand', description='its just a test', guild_ids = [831161440705839124], permissions = [discord.CommandPermission(id=8589934592, type=3)])
async def testcommand(self, ctx, channel : Option(discord.TextChannel, "a normal test", required = True)):
    print("Test passed!")

If anyone knows how I am supposed to use the permissions attribute or another way to disable slash commands that require specific permissions, please let me know!如果有人知道我应该如何使用权限属性或其他方式来禁用需要特定权限的斜杠命令,请告诉我!

I don't know if it changes anything but I'm using Pycord 2.0.0b5我不知道它是否有任何改变,但我使用的是 Pycord 2.0.0b5

Looking at the source code for the permission decorator , it becomes apparent that your type integer is invalid (not sure why they didn't write any validation or documentation for this, I guess they anticipated everyone would use the @permissions decorators)查看权限装饰器的源代码,很明显您的type integer 无效(不确定他们为什么不为此编写任何验证或文档,我猜他们预计每个人都会使用@permissions装饰器)

def decorator(func: Callable):
    if not role_id is None:
        app_cmd_perm = CommandPermission(role_id, 1, permission, guild_id)
    elif not user_id is None:
        app_cmd_perm = CommandPermission(user_id, 2, permission, guild_id)
    else:
        raise ValueError("role_id or user_id must be specified!")

If you are trying to whitelist a role, you should provide type 1, if you want to whitelist a user, provide type 2如果您尝试将角色列入白名单,则应提供类型 1,如果您想将用户列入白名单,请提供类型 2


On a side note, Discord have just released their improved slash command permission system allowing you much, much more flexibility on who can use which command and where.附带一提,Discord 刚刚发布了他们改进的斜杠命令权限系统,让您可以更加灵活地决定谁可以使用哪个命令以及在哪里使用。 It will probably be a bit until this is supported by Pycord, but you might want to keep an eye on this in the next weeks在 Pycord 支持之前可能需要一段时间,但您可能希望在接下来的几周内关注这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM