mehlbot package
Submodules
mehlbot.command module
Contains Command class and bot commands as a global variable.
Also adds ‘help’ to print all added commands to bot_commands.
- class mehlbot.command.Command[source]
Bases:
object
The Commands class, that contains the data needed for a discord command.
- allowed_num_args: List[List[str]] = []
- callback: Callable
- command_name: str = ''
- description: str = ''
- var_args: bool = False
- mehlbot.command.add_command(command_name: str, callback: Callable, allowed_num_args: List[List[str]], description: str = '', var_args: None | bool = None)[source]
The interface/method to add commands to the bot. ‘help’ command gets added when importing this module.
A basic example to add a command can be seen here:
# called with “next”. No args allowed/required. add_command(“next”,
_next, allowed_num_args=[[]], description=”This plays the next song in the current playlist.”
)
A more complex example is the following:
# This either requires 1 argument or 2 arguments. # The described command removes a song, # or when called with 2 arguments, it removes the song from the given playlist. add_command(“remove”,
_remove, allowed_num_args=[[“song_name”], [“playlist”, “song_name”]], description=”Removes selected song from chosen playlist.”
)
- Parameters:
command_name – name of the command, doesn’t require any prefix.
callback – the function that gets called when the command is invoked.
allowed_num_args – array of string-arrays containing the argument name. See example can be seen above.
description – optional description to the command
var_args – allow multiple (unnamed) arguments
- Returns:
mehlbot.command_callback module
The command processor.
Contains methods to process the Commands in command.py.
- async mehlbot.command_callback.method_name(command: Command, command_keys: list[str], entered_command_keys: list[str])[source]
Check if the command matches any.
- Parameters:
command –
command_keys –
entered_command_keys –
- Returns:
- async mehlbot.command_callback.process_command(client: Client, commands: dict[str, mehlbot.command.Command], message: Message) bool [source]
Processes the message with the given commands. For usage see the.
/example directory.
- Parameters:
client – discord.Client
commands – bot_commands, unless using custom commands storage.
message – received message.
- Returns:
True if message is command
mehlbot.logger module
The package’s logger utility to set up a logger.