Skip to main content

A system for making more dynamic and complex checks on discord.py commands

Project description

Install

pip install dpy-check

Docs

PENDING... Until then, here is some implementation code:

import dpycheck as chk
from discord.ext import commands


bot = commands.Bot(...)

# if the error handler has been attached to an object,
# it can be acquired through `ErrorHandler.get(object)`
error_handler = chk.ErrorHandler(..., attach_to=bot)


@bot.command()
@chk.ctx.Check.all(
    chk.user_has_role(...),
    chk.Any(
        chk.membership("d") >= 5,
        chk.user_has_channel_perms(...)
    )
)
async def cmd(...): ...
cmd.error(error_handler.error)

bot.run(...)

When using extensions, you must use .placeholder in combination with resolve_placeholders if you want to use the error handler:

import dpycheck as chk
from discord.ext import commands


class mycog(commands.Cog):
    def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot
        # get the attached ErrorHandler and run `resolve_placeholders`
        chk.ErrorHandler.get(bot).resolve_placeholders(self)
    
    # we use a placeholder and resolve in `__init__`
    # to attach the error handler. Make sure the
    # placeholder is at the very top (or more specifically,
    # make sure it happens *after* the command is created)
    @chk.ErrorHandler.placeholder
    @chk.ctx.Check.all(
        10 >= chk.membership("m") >= 5,
        chk.in_channel(...),
        chk.Not(chk.user_has_role(...))
    )
    @commands.command()
    async def cmd(...): ...


async def setup(...):...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dpy-check-0.0.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

dpy_check-0.0.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file dpy-check-0.0.2.tar.gz.

File metadata

  • Download URL: dpy-check-0.0.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for dpy-check-0.0.2.tar.gz
Algorithm Hash digest
SHA256 12a0a50a0ebe3649cd5eac6f72b7979f67d71084a26ac176b2e70b46119e3853
MD5 77b1e4f8fb558428423b776701ce6ca1
BLAKE2b-256 8c47752522048f577d668294c5ef981b6d9f5b0c8d8fff1df0d7ceba6f43455e

See more details on using hashes here.

File details

Details for the file dpy_check-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dpy_check-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for dpy_check-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f44e8645f1ff01047ec26106c92d7f4ae39d94e6191b8d1c4b3c797c7ce00ab9
MD5 5fe84a88b2766375b7b67a9179b61cfe
BLAKE2b-256 3f56474d71fab564b62df491f85a0539393e7591fa9d0f37277c333defcbc354

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page