Bot

RedBase

class redbot.core.bot.RedBase(*args, cli_flags=None, bot_dir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/red-discordbot/checkouts/latest/docs'), **kwargs)[source]

Bases: redbot.core.commands.commands.GroupMixin, discord.ext.commands.bot.BotBase, redbot.core.rpc.RPCMixin

Mixin for the main bot class.

This exists because Red inherits from discord.AutoShardedClient, which is something other bot classes may not want to have as a parent class.

register_rpc_handler(method)

Registers a method to act as an RPC handler if the internal RPC server is active.

When calling this method through the RPC server, use the naming scheme “cogname__methodname”.

Important

All parameters to RPC handler methods must be JSON serializable objects. The return value of handler methods must also be JSON serializable.

Parameters:method (coroutine) – The method to register with the internal RPC server.
unregister_rpc_handler(method)

Unregisters an RPC method handler.

This will be called automatically for you on cog unload and will pass silently if the method is not previously registered.

Parameters:method (coroutine) – The method to unregister from the internal RPC server.
add_cog(cog)[source]

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.
add_command(command)[source]

Adds a Command or its subclasses into the internal list of commands.

This is usually not called, instead the command() or group() shortcut decorators are used instead.

Parameters:

command (Command) – The command to add.

Raises:
  • ClientException – If the command is already registered.
  • TypeError – If the command passed is not a subclass of Command.
add_permissions_hook(hook)[source]

Add a permissions hook.

Permissions hooks are check predicates which are called before calling Requires.verify, and they can optionally return an override: True to allow, False to deny, and None to default to normal behaviour.

Parameters:hook – A command check predicate which returns True, False or None.
clear_permission_rules(guild_id)[source]

Clear all permission overrides in a scope.

Parameters:guild_id (Optional[int]) – The guild ID to wipe permission overrides for. If None, this will clear all global rules and leave all guild rules untouched.
await embed_requested(channel, user, command=None)[source]

Determine if an embed is requested for a response.

Parameters:
Returns:

True if an embed is requested

Return type:

bool

await get_admin_role_ids(guild_id)[source]

Gets the admin role ids for a guild id.

await get_admin_roles(guild)[source]

Gets the admin roles for a guild.

await get_embed_color(location)[source]

Get the embed color for a location.

Parameters:location (discord.abc.Messageable) –
Returns:
Return type:discord.Color
await get_embed_colour(location)

Get the embed color for a location.

Parameters:location (discord.abc.Messageable) –
Returns:
Return type:discord.Color
await get_mod_role_ids(guild_id)[source]

Gets the mod role ids for a guild id.

await get_mod_roles(guild)[source]

Gets the mod roles for a guild.

await get_owner_notification_destinations()[source]

Gets the users and channels to send to

await get_shared_api_tokens(service_name)[source]

Gets the shared API tokens for a service

Parameters:service_name (str) –
Returns:A Mapping of token names to tokens. This mapping exists because some services have multiple tokens.
Return type:Dict[str, str]
await is_admin(member)[source]

Checks if a member is an admin of their guild.

await is_automod_immune(to_check)[source]

Checks if the user, message, context, or role should be considered immune from automated moderation actions.

This will return False in direct messages.

Parameters:to_check (discord.Message or commands.Context or discord.abc.User or discord.Role) – Something to check if it would be immune
Returns:True if immune
Return type:bool
await is_mod(member)[source]

Checks if a member is a mod or admin of their guild.

await is_owner(user)[source]

Checks if a User or Member is the owner of this bot.

If an owner_id is not set, it is fetched automatically through the use of application_info().

Parameters:user (abc.User) – The user to check for.
Returns:Whether the user is the owner.
Return type:bool
staticmethod list_packages()[source]

Lists packages present in the cogs the folder

await load_extension(spec)[source]

Loads an extension.

An extension is a python module that contains commands, cogs, or listeners.

An extension must have a global function, 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.
  • NoEntryPointError – The extension does not have a setup function.
  • ExtensionFailed – The extension setup function had an execution error.
await process_commands(message)[source]

Same as base method, but dispatches an additional event for cogs which want to handle normal messages differently to command messages, without the overhead of additional get_context calls per cog.

remove_cog(cogname)[source]

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.
remove_command(name)[source]

Remove a Command or subclasses from the internal list of commands.

This could also be used as a way to remove aliases.

Parameters:name (str) – The name of the command to remove.
Returns:The command that was removed. If the name is not valid then None is returned instead.
Return type:Command or subclass
remove_permissions_hook(hook)[source]

Remove a permissions hook.

Parameters are the same as those in add_permissions_hook.

Raises:ValueError – If the permissions hook has not been added.
staticmethod await send_filtered(destination, filter_mass_mentions=True, filter_invite_links=True, filter_all_links=False, **kwargs)[source]

This is a convienience wrapper around

discord.abc.Messageable.send

It takes the destination you’d like to send to, which filters to apply (defaults on mass mentions, and invite links) and any other parameters normally accepted by destination.send

This should realistically only be used for responding using user provided input. (unfortunately, including usernames) Manually crafted messages which dont take any user input have no need of this

await send_help_for(ctx, help_for)[source]

Invokes Red’s helpformatter for a given context and object.

await send_to_owners(content=None, **kwargs)[source]

This sends something to all owners and their configured extra destinations.

This takes the same arguments as discord.abc.Messageable.send

This logs failing sends

await set_shared_api_tokens(service_name, **tokens)[source]

Sets shared API tokens for a service

In most cases, this should not be used. Users should instead be using the set api command

This will not clear existing values not specified.

await verify_permissions_hooks(ctx)[source]

Run permissions hooks.

Parameters:ctx (commands.Context) – The context for the command being invoked.
Returns:False if any hooks returned False, True if any hooks return True and none returned False, None otherwise.
Return type:Optional[bool]

Red

class redbot.core.bot.Red(*args, cli_flags=None, bot_dir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/red-discordbot/checkouts/latest/docs'), **kwargs)[source]

Bases: redbot.core.bot.RedBase, discord.shard.AutoShardedClient

You’re welcome Caleb.

await logout()[source]

Logs out of Discord and closes all connections.

await shutdown(*, restart=False)[source]

Gracefully quit Red.

The program will exit with code 0 by default.

Parameters:restart (bool) – If True, the program will exit with code 26. If the launcher sees this, it will attempt to restart the bot.