Mod log

Mod log has now been separated from Mod for V3.

Basic Usage

from redbot.core import modlog
import discord

class MyCog:
    @commands.command()
    @checks.admin_or_permissions(ban_members=True)
    async def ban(self, ctx, user: discord.Member, reason: str=None):
        await ctx.guild.ban(user)
        case = modlog.create_case(
            ctx.guild, ctx.message.created_at, "ban", user,
            ctx.author, reason, until=None, channel=None
        )
        await ctx.send("Done. It was about time.")

Registering Case types

To register a single case type:

from redbot.core import modlog
import discord

class MyCog:
    def __init__(self, bot):
        ban_case = {
            "name": "ban",
            "default_setting": True,
            "image": ":hammer:",
            "case_str": "Ban",
            "audit_type": "ban"
        }
        modlog.register_casetype(**ban_case)

To register multiple case types:

from redbot.core import modlog
import discord

class MyCog:
    def __init__(self, bot):
        new_types = [
            {
                "name": "ban",
                "default_setting": True,
                "image": ":hammer:",
                "case_str": "Ban",
                "audit_type": "ban"
            },
            {
                "name": "kick",
                "default_setting": True,
                "image": ":boot:",
                "case_str": "Kick",
                "audit_type": "kick"
            }
        ]
        modlog.register_casetypes(new_types)

Important

Image should be the emoji you want to represent your case type with.

API Reference

Mod log

class redbot.core.modlog.Case(bot: redbot.core.bot.Red, guild: discord.guild.Guild, created_at: int, action_type: str, user: discord.user.User, moderator: discord.member.Member, case_number: int, reason: str = None, until: int = None, channel: discord.channel.TextChannel = None, amended_by: discord.member.Member = None, modified_at: int = None, message: discord.message.Message = None)[source]

A single mod log case

coroutine edit(data: dict)[source]

Edits a case

Parameters:data (dict) – The attributes to change
coroutine from_json(mod_channel: discord.channel.TextChannel, bot: redbot.core.bot.Red, data: dict)[source]

Get a Case object from the provided information

Parameters:
  • mod_channel (discord.TextChannel) – The mod log channel for the guild
  • bot (Red) – The bot’s instance. Needed to get the target user
  • data (dict) – The JSON representation of the case to be gotten
Returns:

The case object for the requested case

Return type:

Case

coroutine message_content(embed: bool = True)[source]

Format a case message

Parameters:embed (bool) – Whether or not to get an embed
Returns:A rich embed or string representing a case message
Return type:discord.Embed or str
to_json() → dict[source]

Transform the object to a dict

Returns:The case in the form of a dict
Return type:dict
class redbot.core.modlog.CaseType(name: str, default_setting: bool, image: str, case_str: str, audit_type: str = None, guild: discord.guild.Guild = None)[source]

A single case type

name

The name of the case

Type:str
default_setting

Whether the case type should be on (if True) or off (if False) by default

Type:bool
image

The emoji to use for the case type (for example, :boot:)

Type:str
case_str

The string representation of the case (example: Ban)

Type:str
audit_type

The action type of the action as it would appear in the audit log

Type:str, optional
classmethod from_json(data: dict)[source]
Parameters:data (dict) – The data to create an instance from
Returns:
Return type:CaseType
coroutine is_enabled() → bool[source]

Determines if the case is enabled. If the guild is not set, this will always return False

Returns:True if the guild is set and the casetype is enabled for the guild

False if the guild is not set or if the guild is set and the type is disabled

Return type:bool
coroutine set_enabled(enabled: bool)[source]

Sets the case as enabled or disabled

Parameters:enabled (bool) – True if the case should be enabled, otherwise False
coroutine to_json()[source]

Transforms the case type into a dict and saves it

coroutine redbot.core.modlog.get_next_case_number(guild: discord.guild.Guild) → str[source]

Gets the next case number

Parameters:guild (discord.Guild) – The guild to get the next case number for
Returns:The next case number
Return type:str
coroutine redbot.core.modlog.get_case(case_number: int, guild: discord.guild.Guild, bot: redbot.core.bot.Red) → redbot.core.modlog.Case[source]

Gets the case with the associated case number

Parameters:
  • case_number (int) – The case number for the case to get
  • guild (discord.Guild) – The guild to get the case from
  • bot (Red) – The bot’s instance
Returns:

The case associated with the case number

Return type:

Case

Raises:

RuntimeError – If there is no case for the specified number

coroutine redbot.core.modlog.get_all_cases(guild: discord.guild.Guild, bot: redbot.core.bot.Red) → List[redbot.core.modlog.Case][source]

Gets all cases for the specified guild

Parameters:
  • guild (discord.Guild) – The guild to get the cases from
  • bot (Red) – The bot’s instance
Returns:

A list of all cases for the guild

Return type:

list

coroutine redbot.core.modlog.create_case(bot: redbot.core.bot.Red, guild: discord.guild.Guild, created_at: datetime.datetime, action_type: str, user: Union[discord.user.User, discord.member.Member], moderator: discord.member.Member = None, reason: str = None, until: datetime.datetime = None, channel: discord.channel.TextChannel = None) → Optional[redbot.core.modlog.Case][source]

Creates a new case.

This fires an event on_modlog_case_create

Parameters:
  • bot (Red) – The bot object
  • guild (discord.Guild) – The guild the action was taken in
  • created_at (datetime) – The time the action occurred at
  • action_type (str) – The type of action that was taken
  • user (discord.User or discord.Member) – The user target by the action
  • moderator (discord.Member) – The moderator who took the action
  • reason (str) – The reason the action was taken
  • until (datetime) – The time the action is in effect until
  • channel (discord.TextChannel or discord.VoiceChannel) – The channel the action was taken in
coroutine redbot.core.modlog.get_casetype(name: str, guild: discord.guild.Guild = None) → Optional[redbot.core.modlog.CaseType][source]

Gets the case type

Parameters:
  • name (str) – The name of the case type to get
  • guild (discord.Guild) – If provided, sets the case type’s guild attribute to this guild
Returns:

Return type:

CaseType or None

coroutine redbot.core.modlog.get_all_casetypes(guild: discord.guild.Guild = None) → List[redbot.core.modlog.CaseType][source]

Get all currently registered case types

Returns:A list of case types
Return type:list
coroutine redbot.core.modlog.register_casetype(name: str, default_setting: bool, image: str, case_str: str, audit_type: str = None) → redbot.core.modlog.CaseType[source]

Registers a case type. If the case type exists and there are differences between the values passed and what is stored already, the case type will be updated with the new values

Parameters:
  • name (str) – The name of the case
  • default_setting (bool) – Whether the case type should be on (if True) or off (if False) by default
  • image (str) – The emoji to use for the case type (for example, :boot:)
  • case_str (str) – The string representation of the case (example: Ban)
  • audit_type (str, optional) – The action type of the action as it would appear in the audit log
Returns:

The case type that was registered

Return type:

CaseType

Raises:
coroutine redbot.core.modlog.register_casetypes(new_types: List[dict]) → List[redbot.core.modlog.CaseType][source]

Registers multiple case types

Parameters:

new_types (list) – The new types to register

Returns:

True if all were registered successfully

Return type:

bool

Raises:
coroutine redbot.core.modlog.get_modlog_channel(guild: discord.guild.Guild) → discord.channel.TextChannel[source]

Get the current modlog channel.

Parameters:guild (discord.Guild) – The guild to get the modlog channel for.
Returns:The channel object representing the modlog channel.
Return type:discord.TextChannel
Raises:RuntimeError – If the modlog channel is not found.
coroutine redbot.core.modlog.set_modlog_channel(guild: discord.guild.Guild, channel: Optional[discord.channel.TextChannel]) → bool[source]

Changes the modlog channel

Parameters:
Returns:

True if successful

Return type:

bool

coroutine redbot.core.modlog.reset_cases(guild: discord.guild.Guild) → bool[source]

Wipes all modlog cases for the specified guild

Parameters:guild (discord.Guild) – The guild to reset cases for
Returns:True if successful
Return type:bool