#Slash Command Check Fail

1 messages · Page 1 of 1 (latest)

tidal thistle
#
    @commands.slash_command(
        name="modify",
        description="Modify a User."[:99],
        dm_permission=False,
        guild_ids=guild_ids(),
    )
    @commands.check(check_moderator_predicate)
def check_moderator_predicate(context):
    return is_moderator(context.author)
def is_moderator(member: Member) -> bool:
    """Check if a User is a Moderator."""
    member_role_ids = [role.id for role in member.roles]
    for moderator_role_id in get_moderator_roles():
        if moderator_role_id in member_role_ids:
            return True
    return False

I want to use the same check for prefix/slash commands. The decorator didn't afect the command's output to a non-moderator user.

Goal:

  • Slash Command Checks, check if User has a Role
blissful pivot
#

what exactly is the iussue?

#

also

#
if any(moderator_role_id == role.id for role in member.roles):
tidal thistle
versed cedar
#

Because check only works for context commands.

#

-d slash_command_check

grim shoalBOT
#

slash_command_check(func)```
Similar to [`check()`](https://docs.disnake.dev/en/latest/ext/commands/api/bots.html#disnake.ext.commands.Bot.check "disnake.ext.commands.Bot.check") but for slash commands.
tidal thistle
tawny stratus
#

the @commands.check decorator works for slash commands, but the bot-level one doesn't

#

your code seems fine at first glance

versed cedar
#

Ah, so it does.

#

But either way it should raise a commands.CheckFailure which you then have to handle.

tidal thistle
#

It's as if the check isn't there, the command is available and executes for Non-Moderators. Anything I can test for to see where I'm going wrong?