当前位置: 首页>>代码示例>>Python>>正文


Python commands.check方法代码示例

本文整理汇总了Python中discord.ext.commands.check方法的典型用法代码示例。如果您正苦于以下问题:Python commands.check方法的具体用法?Python commands.check怎么用?Python commands.check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在discord.ext.commands的用法示例。


在下文中一共展示了commands.check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: is_premium

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def is_premium():
    async def predicate(ctx):
        async with ctx.bot.pool.acquire() as conn:
            res = await conn.fetch("SELECT guild FROM premium")
        all_premium = []
        for row in res:
            all_premium.extend(row[0])
        if ctx.guild.id not in all_premium:
            await ctx.send(
                embed=discord.Embed(
                    description="This server does not have premium. Want to get premium? More information "
                    f"is available with the `{ctx.prefix}premium` command.",
                    colour=ctx.bot.error_colour,
                )
            )
            return False
        else:
            return True

    return commands.check(predicate) 
开发者ID:CHamburr,项目名称:modmail,代码行数:22,代码来源:checks.py

示例2: is_patron

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def is_patron():
    async def predicate(ctx):
        async with ctx.bot.pool.acquire() as conn:
            res = await conn.fetchrow("SELECT identifier FROM premium WHERE identifier=$1", ctx.author.id)
        if res:
            return True
        slots = await ctx.bot.tools.get_premium_slots(ctx.bot, ctx.author.id)
        if slots is False:
            await ctx.send(
                embed=discord.Embed(
                    description="This command requires you to be a patron. Want to become a patron? More "
                    f"information is available with the `{ctx.prefix}premium` command.",
                    colour=ctx.bot.error_colour,
                )
            )
            return False
        else:
            async with ctx.bot.pool.acquire() as conn:
                await conn.execute(
                    "INSERT INTO premium (identifier, guild) VALUES ($1, $2)", ctx.author.id, [],
                )
            return True

    return commands.check(predicate) 
开发者ID:CHamburr,项目名称:modmail,代码行数:26,代码来源:checks.py

示例3: is_mod

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def is_mod():
    async def predicate(ctx):
        has_role = False
        roles = (await ctx.bot.get_data(ctx.guild.id))[3]
        for role in roles:
            role = ctx.guild.get_role(role)
            if not role:
                continue
            if role in ctx.author.roles:
                has_role = True
                break
        if has_role is False and ctx.author.guild_permissions.administrator is False:
            await ctx.send(
                embed=discord.Embed(
                    description=f"You do not have access to use this command.", colour=ctx.bot.error_colour,
                )
            )
            return False
        else:
            return True

    return commands.check(predicate) 
开发者ID:CHamburr,项目名称:modmail,代码行数:24,代码来源:checks.py

示例4: had_giveback

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def had_giveback():
    async def predicate(ctx):
        # await ctx.bot.wait_until_ready()

        channel = ctx.channel
        player = ctx.author
        if int(await ctx.bot.db.get_stat(channel, player, "banned")) == 1:
            cond = ctx.author.id in ctx.bot.admins  # User is super admin
            cond = cond or ctx.channel.permissions_for(ctx.author).administrator  # User have server administrator permission
            cond = cond or ctx.author.id in await ctx.bot.db.get_admins(ctx.guild)  # User is admin as defined in the database
            if not cond:  # Not even an admin so
                ctx.logger.debug("Banned player trying to play :(")
                return False

        lastGB = int(await ctx.bot.db.get_stat(channel, player, "lastGiveback"))
        if int(lastGB / 86400) != int(int(time.time()) / 86400):
            daygb = int(lastGB / 86400)
            daynow = int(int(time.time()) / 86400)
            ctx.logger.debug(f"Giveback needed : Last GiveBack was on day {daygb}, and we are now on day {daynow}.")
            await ctx.bot.db.giveback(channel=channel, user=player)

        return True

    return commands.check(predicate) 
开发者ID:DuckHunt-discord,项目名称:DHV3,代码行数:26,代码来源:checks.py

示例5: voted_lately

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def voted_lately():
    async def predicate(ctx):
        player = ctx.message.author

        headers = {'authorization': ctx.bot.discordbots_org_key, 'content-type': 'application/json'}

        url = '{0}/bots/{1.user.id}/check?userId={2.id}'.format(DISCORD_BOTS_ORG_API, ctx.bot, player)
        async with session.get(url, headers=headers) as resp:
            cond = bool((await resp.json())['voted'])

        if cond:
            return True
        else:
            raise NoVotesOnDBL

    return commands.check(predicate) 
开发者ID:DuckHunt-discord,项目名称:DHV3,代码行数:18,代码来源:checks.py

示例6: has_permissions

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def has_permissions(permission_level: PermissionLevel = PermissionLevel.REGULAR):
    """
    A decorator that checks if the author has the required permissions.

    Parameters
    ----------

    permission_level : PermissionLevel
        The lowest level of permission needed to use this command.
        Defaults to REGULAR.

    Examples
    --------
    ::
        @has_permissions(PermissionLevel.OWNER)
        async def setup(ctx):
            print("Success")
    """

    return commands.check(has_permissions_predicate(permission_level)) 
开发者ID:kyb3r,项目名称:modmail,代码行数:22,代码来源:checks.py

示例7: thread_only

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def thread_only():
    """
    A decorator that checks if the command
    is being ran within a Modmail thread.
    """

    async def predicate(ctx):
        """
        Parameters
        ----------
        ctx : Context
            The current discord.py `Context`.

        Returns
        -------
        Bool
            `True` if the current `Context` is within a Modmail thread.
            Otherwise, `False`.
        """
        return ctx.thread is not None

    predicate.fail_msg = "This is not a Modmail thread."
    return commands.check(predicate) 
开发者ID:kyb3r,项目名称:modmail,代码行数:25,代码来源:checks.py

示例8: in_month_listener

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def in_month_listener(*allowed_months: Month) -> t.Callable:
    """
    Shield a listener from being invoked outside of `allowed_months`.

    The check is performed against current UTC month.
    """
    def decorator(listener: t.Callable) -> t.Callable:
        @functools.wraps(listener)
        async def guarded_listener(*args, **kwargs) -> None:
            """Wrapped listener will abort if not in allowed month."""
            current_month = resolve_current_month()

            if current_month in allowed_months:
                # Propagate return value although it should always be None
                return await listener(*args, **kwargs)
            else:
                log.debug(f"Guarded {listener.__qualname__} from invoking in {current_month!s}")
        return guarded_listener
    return decorator 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:21,代码来源:decorators.py

示例9: in_month_command

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def in_month_command(*allowed_months: Month) -> t.Callable:
    """
    Check whether the command was invoked in one of `enabled_months`.

    Uses the current UTC month at the time of running the predicate.
    """
    async def predicate(ctx: Context) -> bool:
        current_month = resolve_current_month()
        can_run = current_month in allowed_months

        log.debug(
            f"Command '{ctx.command}' is locked to months {human_months(allowed_months)}. "
            f"Invoking it in month {current_month!s} is {'allowed' if can_run else 'disallowed'}."
        )
        if can_run:
            return True
        else:
            raise InMonthCheckFailure(f"Command can only be used in {human_months(allowed_months)}")

    return commands.check(predicate) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:22,代码来源:decorators.py

示例10: with_role

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def with_role(*role_ids: int) -> t.Callable:
    """Check to see whether the invoking user has any of the roles specified in role_ids."""
    async def predicate(ctx: Context) -> bool:
        if not ctx.guild:  # Return False in a DM
            log.debug(
                f"{ctx.author} tried to use the '{ctx.command.name}'command from a DM. "
                "This command is restricted by the with_role decorator. Rejecting request."
            )
            return False

        for role in ctx.author.roles:
            if role.id in role_ids:
                log.debug(f"{ctx.author} has the '{role.name}' role, and passes the check.")
                return True

        log.debug(
            f"{ctx.author} does not have the required role to use "
            f"the '{ctx.command.name}' command, so the request is rejected."
        )
        return False
    return commands.check(predicate) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:23,代码来源:decorators.py

示例11: without_role

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def without_role(*role_ids: int) -> t.Callable:
    """Check whether the invoking user does not have all of the roles specified in role_ids."""
    async def predicate(ctx: Context) -> bool:
        if not ctx.guild:  # Return False in a DM
            log.debug(
                f"{ctx.author} tried to use the '{ctx.command.name}' command from a DM. "
                "This command is restricted by the without_role decorator. Rejecting request."
            )
            return False

        author_roles = [role.id for role in ctx.author.roles]
        check = all(role not in author_roles for role in role_ids)
        log.debug(
            f"{ctx.author} tried to call the '{ctx.command.name}' command. "
            f"The result of the without_role check was {check}."
        )
        return check
    return commands.check(predicate) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:20,代码来源:decorators.py

示例12: in_whitelist

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def in_whitelist(
    *,
    channels: Container[int] = (),
    categories: Container[int] = (),
    roles: Container[int] = (),
    redirect: Optional[int] = Channels.bot_commands,
    fail_silently: bool = False,
) -> Callable:
    """
    Check if a command was issued in a whitelisted context.

    The whitelists that can be provided are:

    - `channels`: a container with channel ids for whitelisted channels
    - `categories`: a container with category ids for whitelisted categories
    - `roles`: a container with with role ids for whitelisted roles

    If the command was invoked in a context that was not whitelisted, the member is either
    redirected to the `redirect` channel that was passed (default: #bot-commands) or simply
    told that they're not allowed to use this particular command (if `None` was passed).
    """
    def predicate(ctx: Context) -> bool:
        """Check if command was issued in a whitelisted context."""
        return in_whitelist_check(ctx, channels, categories, roles, redirect, fail_silently)

    return commands.check(predicate) 
开发者ID:python-discord,项目名称:bot,代码行数:28,代码来源:decorators.py

示例13: with_role

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def with_role(*role_ids: int) -> Callable:
    """Returns True if the user has any one of the roles in role_ids."""
    async def predicate(ctx: Context) -> bool:
        """With role checker predicate."""
        return with_role_check(ctx, *role_ids)
    return commands.check(predicate) 
开发者ID:python-discord,项目名称:bot,代码行数:8,代码来源:decorators.py

示例14: without_role

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def without_role(*role_ids: int) -> Callable:
    """Returns True if the user does not have any of the roles in role_ids."""
    async def predicate(ctx: Context) -> bool:
        return without_role_check(ctx, *role_ids)
    return commands.check(predicate) 
开发者ID:python-discord,项目名称:bot,代码行数:7,代码来源:decorators.py

示例15: is_owner

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import check [as 别名]
def is_owner():
    def predicate(ctx):
        if author_is_owner(ctx):
            return True
        raise commands.CheckFailure("Only the bot owner may run this command.")

    return commands.check(predicate) 
开发者ID:avrae,项目名称:avrae,代码行数:9,代码来源:checks.py


注:本文中的discord.ext.commands.check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。