Skip to content

RubyBot ​

python
from ruby import RubyBot, run

RubyBot is a discord.ext.commands.Bot subclass. You don't normally create it yourself: python -m ruby calls run(), which makes one and logs in with TOKEN from the environment. Cogs get it as self.bot.

Attributes ​

AttributeTypeWhat it is
cfgConfigThe loaded config.yaml.
dbAsyncDatabaseThe MongoDB database named after cfg.name.
mongoAsyncMongoClientThe client behind db, connected to MONGO_URI.
serverServerShortcut for cfg.server: id, name, invite, channels.
prefixstrThe configured prefix, as written.
namestrcfg.name
friendly_namestrcfg.friendly_name
loggerlogging.LoggerWrites to bot.log. See Logging.
utilsmoduleruby.utils, for cogs that would rather not import it.
status_tasktasks.LoopRotates cfg.statuses every cfg.status_interval seconds. Started on the first on_ready.

Everything from commands.Bot is there too: get_channel, is_owner, tree, wait_until_ready, and so on.

Methods ​

await bot.log(level, msg) ​

Logs msg to bot.log and, if level is at least cfg.log_level and a log channel is set, to the log channel as an embed.

python
await self.bot.log(logging.WARNING, "Couldn't find the bump channel")

await bot.discord_log(level, msg) ​

Just the Discord half of log(). Rarely needed on its own.

await bot.load_cogs() ​

Loads every cogs/*.py that doesn't start with _, logging failures instead of raising. Called for you from setup_hook.

Intents ​

RubyBot uses discord.Intents.default() plus message_content and members. Both are privileged and must be enabled in the Developer Portal.

Event handlers Ruby defines ​

If a cog wants to react to these events, add a @commands.Cog.listener(). Overriding them on the bot replaces Ruby's handling.

EventWhat Ruby does
setup_hookLoads cogs.
on_readyLogs the login, starts the status loop (once, even after reconnects) and syncs the slash commands with Discord.
on_command_completionLogs the command at DEBUG.
on_command_errorThe friendly error replies: see Errors and replies.
tree.on_errorSends plain slash command errors to on_command_error, so they get the same handling.