Chat Command Middleware#
A selection of preimplemented chat command middleware.
Note
See Chat - Introduction to Middleware for a more detailed walkthough on how to use these.
Available Middleware#
Middleware |
Description |
|---|---|
Filters in which channels a command can be executed in. |
|
Filters which users can execute a command. |
|
Restricts the use of commands to only the streamer in their channel. |
|
Restricts a command to only be executed once every |
|
Restricts a command to be only executed once every |
|
Restricts a command to be only executed once every |
Class Documentation#
- class twitchAPI.chat.middleware.BaseCommandMiddleware#
Bases:
ABCThe base for chat command middleware, extend from this when implementing your own
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- abstract async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- abstract async was_executed(command)#
Will be called when a command was executed, use to update internal state
-
execute_blocked_handler:
- class twitchAPI.chat.middleware.ChannelRestriction#
Bases:
BaseCommandMiddlewareFilters in which channels a command can be executed in
- __init__(allowed_channel=None, denied_channel=None, execute_blocked_handler=None)#
- Parameters:
allowed_channel¶ (
Optional[List[str]]) – if provided, the command can only be used in channels on this listdenied_channel¶ (
Optional[List[str]]) – if provided, the command can’t be used in channels on this listexecute_blocked_handler¶ (
Optional[Callable[[ChatCommand],Awaitable[None]]]) – optional specific handler for when the execution is blocked
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- async was_executed(command)#
Will be called when a command was executed, use to update internal state
- class twitchAPI.chat.middleware.UserRestriction#
Bases:
BaseCommandMiddlewareFilters which users can execute a command
- __init__(allowed_users=None, denied_users=None, execute_blocked_handler=None)#
- Parameters:
allowed_users¶ (
Optional[List[str]]) – if provided, the command can only be used by one of the provided usersdenied_users¶ (
Optional[List[str]]) – if provided, the command can not be used by any of the provided usersexecute_blocked_handler¶ (
Optional[Callable[[ChatCommand],Awaitable[None]]]) – optional specific handler for when the execution is blocked
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- async was_executed(command)#
Will be called when a command was executed, use to update internal state
- class twitchAPI.chat.middleware.StreamerOnly#
Bases:
BaseCommandMiddlewareRestricts the use of commands to only the streamer in their channel
- __init__(execute_blocked_handler=None)#
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- async was_executed(command)#
Will be called when a command was executed, use to update internal state
- class twitchAPI.chat.middleware.ChannelCommandCooldown#
Bases:
BaseCommandMiddlewareRestricts a command to only be executed once every
cooldown_secondsin a channel regardless of user.- __init__(cooldown_seconds, execute_blocked_handler=None)#
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- async was_executed(command)#
Will be called when a command was executed, use to update internal state
- class twitchAPI.chat.middleware.ChannelUserCommandCooldown#
Bases:
BaseCommandMiddlewareRestricts a command to be only executed once every
cooldown_secondsin a channel by a user.- __init__(cooldown_seconds, execute_blocked_handler=None)#
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- async was_executed(command)#
Will be called when a command was executed, use to update internal state
- class twitchAPI.chat.middleware.GlobalCommandCooldown#
Bases:
BaseCommandMiddlewareRestricts a command to be only executed once every
cooldown_secondsin any channel- __init__(cooldown_seconds, execute_blocked_handler=None)#
-
execute_blocked_handler:
Optional[Callable[[ChatCommand],Awaitable[None]]] = None# If set, this handler will be called should
can_execute()fail.
- async can_execute(command)#
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
- async was_executed(command)#
Will be called when a command was executed, use to update internal state
Bases:
BaseCommandMiddlewareRestricts commands to only current chat room in Shared Chat streams
return
Trueif the given command should execute, otherwiseFalse- Parameters:
command¶ (
ChatCommand) – The command to check if it should be executed- Return type:
If set, this handler will be called should
can_execute()fail.
Will be called when a command was executed, use to update internal state