Hook ABCs#
HookResult
#
HookResult(abort: bool = False)
The result of a hook.
PARAMETER | DESCRIPTION |
---|---|
abort |
Whether to abort the execution of the command. If True, the command execution will be silently aborted. If this is undesired, you should raise an exception instead.
TYPE:
|
Hookable
#
A trait for objects that can have hooks added to them.
hooks
abstractmethod
property
#
hooks: MutableSequence[HookT[ClientT]]
The pre-execution hooks for this object.
post_hooks
abstractmethod
property
#
post_hooks: MutableSequence[PostHookT[ClientT]]
The post-execution hooks for this object.
add_hook
#
Add a new pre-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns either a HookResult
or
None
can be used as a hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
with_hook
#
with_hook(hook: HookT[ClientT]) -> Callable[[HookableT], HookableT]
Add a new pre-execution hook to a hookable object. It will run before the command callback.
Any function that takes a Context
as its sole parameter
and returns either a HookResult
or
None
can be used as a hook.
with_post_hook
#
with_post_hook(hook: PostHookT[ClientT]) -> Callable[[HookableT], HookableT]
Add a new post-execution hook to a hookable object. It will run after the command callback.
Any function that takes a Context
as its sole parameter
and returns None
can be used as a post-hook.
Post-execution hooks are not executed if a pre-execution hook aborts the execution of the command.
Warning
Post-execution hooks are called even if the command callback raises an exception.
You can see if the command callback failed by checking Context.has_command_failed
.