β‘ RED-DISCORDBOT DEVELOPER QUICK REFERENCE β‘ #
Instant Access Cheat Sheet
π INSTANT SETUP #
pip install Red-DiscordBot
redbot-setup # Interactive setup
redbot <instance_name> # Launch bot
π ESSENTIAL IMPORTS #
from redbot.core import commands, Config, bank
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import box, pagify
from discord.ext import commands as dpy_commands
π§© COG TEMPLATE #
import discord
from redbot.core import commands, Config
class MyCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567890)
default_guild = {"setting": "default_value"}
self.config.register_guild(**default_guild)
@commands.command()
async def mycommand(self, ctx):
"""Command description"""
await ctx.send("Response")
π CONFIG PATTERNS #
# Basic config setup
self.config = Config.get_conf(self, identifier=12345)
self.config.register_global(setting=default)
self.config.register_guild(guild_setting=default)
self.config.register_user(user_setting=default)
# Get/Set values
value = await self.config.setting()
await self.config.setting.set(new_value)
# Nested data
async with self.config.guild(guild).nested() as data:
data["key"] = "value"
π‘οΈ PERMISSION DECORATORS #
@commands.admin() # Admin only
@commands.mod() # Moderator+
@commands.guild_only() # Guild only
@commands.bot_has_permissions(manage_roles=True)
@commands.has_permissions(kick_members=True)
π° ECONOMY INTEGRATION #
from redbot.core import bank
# Check balance
balance = await bank.get_balance(user)
# Transfer credits
await bank.deposit_credits(user, amount)
await bank.withdraw_credits(user, amount)
# Cost decorator
@bank.cost(100)
async def expensive_command(self, ctx):
pass
π― COMMAND TYPES #
# Basic command
@commands.command()
async def basic(self, ctx, arg):
pass
# Group command
@commands.group()
async def group(self, ctx):
pass
@group.command()
async def subcommand(self, ctx):
pass
# Hybrid command (slash + prefix)
@commands.hybrid_command()
async def hybrid(self, ctx, arg: str):
pass
π§ CONVERTERS #
@commands.command()
async def cmd(self, ctx, user: discord.Member, amount: int):
pass
# Custom converter
class MyConverter(commands.Converter):
async def convert(self, ctx, argument):
return processed_argument
π EMBED PATTERNS #
embed = discord.Embed(
title="Title",
description="Description",
color=await ctx.embed_color()
)
embed.add_field(name="Field", value="Value", inline=False)
await ctx.send(embed=embed)
π¨ FORMATTING UTILITIES #
from redbot.core.utils.chat_formatting import box, pagify, humanize_list
# Code blocks
await ctx.send(box("code", lang="python"))
# Pagination
for page in pagify(long_text):
await ctx.send(page)
# Lists
await ctx.send(humanize_list(["item1", "item2", "item3"]))
π EVENT HANDLING #
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
# Handle message
@commands.Cog.listener()
async def on_member_join(self, member):
# Handle new member
pass
ποΈ DATA SCOPES #
GLOBAL- Bot-wide settingsGUILD- Per-server settingsCHANNEL- Per-channel settingsUSER- Per-user settings (global)MEMBER- Per-member settings (guild-specific)ROLE- Per-role settingsCUSTOM- Custom identifier
π ERROR HANDLING #
@commands.command()
async def cmd(self, ctx):
try:
# Command logic
pass
except commands.BadArgument:
await ctx.send("Invalid argument!")
except Exception as e:
await ctx.send(f"Error: {e}")
π¦ COG LIFECYCLE #
async def cog_load(self):
"""Called when cog is loaded"""
pass
async def cog_unload(self):
"""Called when cog is unloaded"""
pass
def cog_check(self, ctx):
"""Check for all commands in cog"""
return True
π΅ AUDIO COG BASICS #
from redbot.cogs.audio.core.abc import MixinMeta
class AudioCog(MixinMeta):
def __init__(self, bot):
self.bot = bot
super().__init__()
π§ DEBUGGING TIPS #
- Use
[p]load devfor development tools [p]reload cog_nameto reload cog during development- Check logs in data directory
- Use
print()statements for quick debugging await ctx.tick()for success confirmation
π KEY DOCUMENTATION PATHS #
- Official Docs: docs.discord.red
- API Reference: redbot.readthedocs.io
- Cog Creation Guide: docs.discord.red/en/stable/guide_cog_creation.html
- Config Tutorial: docs.discord.red/en/stable/framework_config.html
π¨ COMMON GOTCHAS #
- Always use
ctx.send()instead ofchannel.send()when possible - Register config defaults before first access
- Use
guild_only()for guild-specific commands - Check permissions before attempting Discord actions
- Use async context managers for config modifications
β‘ Keep this reference handy for rapid Red-DiscordBot development