curious.commands.manager¶
Contains the class for the commands manager for a client.
Classes
CommandsManager (client, *[, message_check]) |
A manager that handles commands for a client. |
-
class
curious.commands.manager.
CommandsManager
(client: curious.core.client.Client, *, message_check=None, command_prefix: str = None)[source]¶ Bases:
object
A manager that handles commands for a client.
First, you need to create the manager and attach it to a client:
# form 1, automatically register with the client manager = CommandsManager.with_client(bot) # form 2, manually register manager = CommandsManager(bot) manager.register_events()
This is required to add the handler events to the client.
Next, you need to register a message check handler. This is a callable that is called for every message to try and extract the command from a message, if it matches. By default, the manager provides an easy way to use a simple command prefix:
# at creation time manager = CommandsManager(bot, command_prefix="!") # or set it on the manager manager.command_prefix = "!"
At this point, the command prefix will be available on the manager with either
Manager.command_prefix
orManager.message_check.prefix
.If you need more complex message checking, you can use
message_check
:manager = CommandsManager(bot, message_check=my_message_checker) # or manager.message_check = my_message_checker
Finally, you can register plugins or modules containing plugins with the manager:
@bot.event("ready") async def load_plugins(ctx: EventContext): # load plugin explicitly await manager.load_plugin(PluginClass, arg1) # load plugins from a module await manager.load_plugins_from("my.plugin.module")
You can also add free-standing commands that aren’t bound to a plugin with
CommandsManager.add_command()
:@command() async def ping(ctx: CommandsContext): await ctx.channel.messages.send(content="Ping!") manager.add_command(ping)
These will then be available to the client.
Parameters: -
get_command
(command_name)[source]¶ Gets a command from the internal command storage. If provided a string separated by spaces, a subcommand lookup will be attempted.
Parameters: command_name ( str
) – The name of the command to lookup.
-
await
handle_message
(ctx, message)[source]¶ Registered as the event handler in a client for handling commands.
-
await
load_plugin
(klass, *args, module=None)[source]¶ Loads a plugin.
Note
The client instance will automatically be provided to the Plugin’s
__init__
.Parameters:
-
await
load_plugins_from
(import_path)[source]¶ Loads plugins from the specified module.
Parameters: import_path ( str
) – The import path to import.
-
register_events
()[source]¶ Copies the events to the client specified on this manager.
Return type: None
-
remove_command
(command)[source]¶ Removes a command.
Parameters: command – The name of the command, or the command function.
-
await
unload_plugin
(klass)[source]¶ Unloads a plugin.
Parameters: klass ( Union
[Plugin
,str
]) – The plugin class or name of plugin to unload.
-