Exemple #1
0
async def _has_guild_permissions(ctx: context.Context, *, permissions: hikari.Permissions):
    if not (ctx.bot.intents & hikari.Intents.GUILDS) == hikari.Intents.GUILDS:
        raise hikari.MissingIntentError(hikari.Intents.GUILDS)

    await _guild_only(ctx)

    roles = ctx.bot.cache.get_roles_view_for_guild(ctx.guild_id).values()
    missing_perms = _get_missing_perms(permissions, [role for role in roles if role.id in ctx.member.role_ids])

    if missing_perms:
        raise errors.MissingRequiredPermission(
            "You are missing one or more permissions required in order to run this command", permissions=missing_perms
        )
    return True
Exemple #2
0
async def _has_permissions(ctx: context.Context, *, permissions: hikari.Permissions) -> bool:
    if not (ctx.bot.intents & hikari.Intents.GUILDS) == hikari.Intents.GUILDS:
        raise hikari.MissingIntentError(hikari.Intents.GUILDS)

    await _guild_only(ctx)

    perm_over = ctx.channel.permission_overwrites.values()
    perm_none = hikari.Permissions.NONE

    allowed_perms = functools.reduce(
        operator.or_, (override.allow if override.id in ctx.member.role_ids else perm_none for override in perm_over)
    )

    missing_perms = allowed_perms ^ permissions

    if missing_perms:
        raise errors.MissingRequiredPermission(
            "You are missing one or more permissions required in order to run this command", permissions=missing_perms
        )
    return True