Skip to main content

Bot

class Bot(GroupMixin, Client)
Represents a fortnite bot. This class is a subclass of rebootpy.Client and as a result anything that you can do with a rebootpy.Client you can do with this bot. This class also subclasses GroupMixin to provide the functionality to manage commands.

Parameters

command_prefix
Any
required
The command prefix is what the message content must contain initially to have a command invoked. This prefix could either be a string to indicate what the prefix should be, or a callable that takes in the bot as its first parameter and rebootpy.FriendMessage or rebootpy.PartyMessage as its second parameter and returns the prefix. This is to facilitate “dynamic” command prefixes. This callable can be either a regular function or a coroutine.An empty string as the prefix always matches, enabling prefix-less command invocation.The command prefix could also be an iterable of strings indicating that multiple checks for the prefix should be used and the first one to match will be the invocation prefix.
auth
Auth
required
The authentication instance to use for the bot.
help_command
Optional[HelpCommand]
The help command implementation to use. This can be dynamically set at runtime. To remove the help command pass None.
description
Optional[str]
The content prefixed into the default help message.
case_insensitive
bool
default:"False"
Whether the commands should be case insensitive. This attribute does not carry over to groups. You must set it to every group if you require group commands to be case insensitive as well.
owner_id
Optional[int]
The user ID that owns the bot. This is used by is_owner() and checks that call this method. You cannot set both owner_id and owner_ids.
owner_ids
Optional[Collection[int]]
The user IDs that owns the bot. This is similar to owner_id. For performance reasons it is recommended to use a set for the collection. You cannot set both owner_id and owner_ids.

Attributes

command_prefix
Any
The command prefix for the bot.
description
str
The content prefixed into the default help message.
help_command
Optional[HelpCommand]
The help command implementation being used.
owner_id
Optional[int]
The user ID that owns the bot.
owner_ids
Optional[Collection[int]]
The user IDs that own the bot.
cogs
Mapping[str, Cog]
A read-only mapping of cog name to cog.
extensions
Mapping[str, types.ModuleType]
A read-only mapping of extension name to extension.

Methods

check

@bot.check
def func(ctx: Context) -> bool:
    ...
A decorator that adds a check globally to every command. This function takes a single parameter, Context, and can only raise exceptions inherited from CommandError. Parameters:
  • func: The function that will be used as a global check. Can be either a regular function or a coroutine.
Example:
@bot.check
def global_check(ctx):
    # Allows only party commands.
    return ctx.party is not None

add_check

bot.add_check(func, *, call_once=False)
Adds a global check to the bot. This is the non-decorator interface to check() and check_once(). Parameters:
  • func: The function that was used as a global check.
  • call_once (bool): If the function should only be called once per Command.invoke() call.

remove_check

bot.remove_check(func, *, call_once=False)
Removes a global check from the bot. Parameters:
  • func: The function to remove from the global checks.
  • call_once (bool): If the function was added with call_once=True in the add_check() call or using check_once().

check_once

@bot.check_once
def func(ctx: Context) -> bool:
    ...
A decorator that adds a “call once” global check to the bot. Unlike regular global checks, this one is called only once per Command.invoke() call. Example:
@bot.check_once
def whitelist(ctx):
    return ctx.message.author.id in my_whitelist

is_owner

await bot.is_owner(user_id)
Checks if a user id is the owner of the bot. Parameters:
  • user_id (str): The user id to check for.
Returns: bool - Whether the user is the owner.

before_invoke

@bot.before_invoke
async def func(ctx: Context):
    ...
A decorator that registers a coroutine as a pre-invoke hook. A pre-invoke hook is called directly before the command is called. This makes it a useful function to set up database connections or any type of set up required. This pre-invoke hook takes a sole parameter, a Context. Note: The before_invoke() and after_invoke() hooks are only called if all checks and argument parsing procedures pass without error. Raises: TypeError - The coroutine passed is not actually a coroutine.

after_invoke

@bot.after_invoke
async def func(ctx: Context):
    ...
A decorator that registers a coroutine as a post-invoke hook. A post-invoke hook is called directly after the command is called. This makes it a useful function to clean-up database connections or any type of clean up required. This post-invoke hook takes a sole parameter, a Context. Note: This is not called unless checks and argument parsing procedures succeed. This hook is, however, always called regardless of the internal command callback raising an error. Raises: TypeError - The coroutine passed is not actually a coroutine.

add_cog

bot.add_cog(cog)
Adds a “cog” to the bot. A cog is a class that has its own event listeners and commands. Parameters:
  • cog (Cog): The cog to register to the bot.
Raises:
  • TypeError: The cog does not inherit from Cog.
  • CommandError: An error happened during loading.

remove_cog

bot.remove_cog(name)
Removes a cog from the bot. All registered commands and event listeners that the cog has registered will be removed as well. If no cog is found then this method has no effect. Parameters:
  • name (str): The name of the cog to remove.

get_cog

bot.get_cog(name)
Gets the cog instance requested. If the cog is not found, None is returned instead. Parameters:
  • name (str): The name of the cog you are requesting. This is equivalent to the name passed via keyword argument in class creation or the class name if unspecified.
Returns: Optional[Cog] - The cog instance, or None if not found.

load_extension

bot.load_extension(name)
Loads an extension. An extension is a python module that contains commands, cogs, or listeners. An extension must have a global function, extension_setup defined as the entry point on what to do when the extension is loaded. This entry point must have a single argument, the bot. Parameters:
  • name (str): The extension name to load. It must be dot separated like regular Python imports if accessing a sub-module. e.g. foo.test if you want to import foo/test.py.
Raises:
  • ExtensionNotFound: The extension could not be imported.
  • ExtensionAlreadyLoaded: The extension is already loaded.
  • ExtensionMissingEntryPoint: The extension does not have a extension_setup function.
  • ExtensionFailed: The extension or its setup function had an execution error.

unload_extension

bot.unload_extension(name)
Unloads an extension. When the extension is unloaded, all commands, listeners, and cogs are removed from the bot and the module is un-imported. The extension can provide an optional global function, cog_teardown, to do miscellaneous clean-up if necessary. This function takes a single parameter, the bot, similar to extension_setup from load_extension(). Parameters:
  • name (str): The extension name to unload. It must be dot separated like regular Python imports if accessing a sub-module. e.g. foo.test if you want to import foo/test.py.
Raises:
  • ExtensionNotLoaded: The extension was not loaded.

reload_extension

bot.reload_extension(name)
Atomically reloads an extension. This replaces the extension with the same extension, only refreshed. This is equivalent to a unload_extension() followed by a load_extension() except done in an atomic way. That is, if an operation fails mid-reload then the bot will roll-back to the prior working state. Parameters:
  • name (str): The extension name to reload. It must be dot separated like regular Python imports if accessing a sub-module. e.g. foo.test if you want to import foo/test.py.
Raises:
  • ExtensionNotLoaded: The extension was not loaded.
  • ExtensionNotFound: The extension could not be imported.
  • ExtensionMissingEntryPoint: The extension does not have a extension_setup function.
  • ExtensionFailed: The extension setup function had an execution error.

get_prefix

await bot.get_prefix(message)
Retrieves the prefix the bot is listening to with the message as a context. Parameters:
  • message (Union[FriendMessage, PartyMessage]): The message context to get the prefix of.
Returns: Union[List[str], str] - A list of prefixes or a single prefix that the bot is listening for.

get_context

await bot.get_context(message, *, cls=Context)
Returns the invocation context from the message. This is a more low-level counter-part for process_commands() to allow users more fine grained control over the processing. The returned context is not guaranteed to be a valid invocation context, Context.valid must be checked to make sure it is. Parameters:
  • message (Union[FriendMessage, PartyMessage]): The message to get the invocation context from.
  • cls: The factory class that will be used to create the context. By default, this is Context. Should a custom class be provided, it must be similar enough to Context’s interface.
Returns: Context - The invocation context. The type of this can change via the cls parameter.

invoke

await bot.invoke(ctx)
Invokes the command given under the invocation context and handles all the internal event dispatch mechanisms. Parameters:
  • ctx (Context): The invocation context to invoke.

process_commands

await bot.process_commands(message)
This function processes the commands that have been registered to the bot and other groups. Without this coroutine, none of the commands will be triggered. By default, this coroutine is called automatically when a new message is received. This is built using other low level tools, and is equivalent to a call to get_context() followed by a call to invoke(). Parameters:
  • message (Union[FriendMessage, PartyMessage]): The message to process commands for.