Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tanrbobanr/dpy-check
A system for making more dynamic and complex checks on discord.py commands
https://github.com/tanrbobanr/dpy-check
Last synced: about 1 month ago
JSON representation
A system for making more dynamic and complex checks on discord.py commands
- Host: GitHub
- URL: https://github.com/tanrbobanr/dpy-check
- Owner: tanrbobanr
- License: mit
- Created: 2023-01-05T22:10:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-12T23:42:04.000Z (about 2 years ago)
- Last Synced: 2024-11-20T12:50:47.073Z (about 2 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
- awesome-discordpy - tanrbobanr/dpy-check - A system for making more dynamic and complex checks on discord.py commands. (Libraries and Extensions / Utilities)
README
# Install
`pip install dpy-check`
# Docs
PENDING...
Until then, here is some implementation code:
```py
import dpycheck as chk
from discord.ext import commandsbot = 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:*
```py
import dpycheck as chk
from discord.ext import commandsclass 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(...):...
```