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
Release history Release notifications | RSS feed
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.1.tar.gz
(11.4 kB
view hashes)
Built Distribution
dpy_check-0.0.1-py3-none-any.whl
(17.3 kB
view hashes)
Close
Hashes for dpy_check-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2bfd28b7c01dbf41543285b55a375de88737bb764709fa077cb5ed685c838b |
|
MD5 | 0658efc3a608a6c2f9c7bdb4d19292e1 |
|
BLAKE2b-256 | dd4c82d40d68f4692fe4a923f7135086e1ceadbe8f034f2a2d849ac07bf68727 |