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
(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
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:
-
coroutine
message_content
()[source]¶ Format a case message
Returns: A rich embed representing a case message Return type: discord.Embed
-
coroutine
-
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
¶ str – The name of the case
-
image
¶ str – The emoji to use for the case type (for example, :boot:)
-
case_str
¶ str – The string representation of the case (example: Ban)
-
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
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 forReturns: 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: 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) → typing.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: - guild (
-
coroutine
redbot.core.modlog.
create_case
(guild: discord.guild.Guild, created_at: datetime.datetime, action_type: str, user: typing.Union[discord.user.User, discord.member.Member], moderator: discord.member.Member = None, reason: str = None, until: datetime.datetime = None, channel: discord.channel.TextChannel = None) → typing.Union[redbot.core.modlog.Case, NoneType][source]¶ Creates a new case
Parameters: - 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
ordiscord.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
ordiscord.VoiceChannel
) – The channel the action was taken in
Returns: The newly created case
Return type: Raises: RuntimeError
– If the mod log channel doesn’t exist- guild (
-
coroutine
redbot.core.modlog.
get_casetype
(name: str, guild: discord.guild.Guild = None) → typing.Union[redbot.core.modlog.CaseType, NoneType][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:
-
coroutine
redbot.core.modlog.
get_all_casetypes
(guild: discord.guild.Guild = None) → typing.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 (ifFalse
) 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: Raises: RuntimeError
– If the case type is already registered- TypeError: – If a parameter is missing
ValueError
– If a parameter’s value is not validAttributeError
– If the audit_type is not an attribute ofdiscord.AuditLogAction
-
coroutine
redbot.core.modlog.
register_casetypes
(new_types: typing.List[dict]) → typing.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 successfullyReturn type: Raises: See also
-
coroutine
redbot.core.modlog.
get_modlog_channel
(guild: discord.guild.Guild) → typing.Union[discord.channel.TextChannel, NoneType][source]¶ Get the current modlog channel
Parameters: guild ( discord.Guild
) – The guild to get the modlog channel forReturns: The channel object representing the modlog channel Return type: discord.TextChannel
orNone
Raises: RuntimeError
– If the modlog channel is not found
-
coroutine
redbot.core.modlog.
set_modlog_channel
(guild: discord.guild.Guild, channel: typing.Union[discord.channel.TextChannel, NoneType]) → bool[source]¶ Changes the modlog channel
Parameters: - guild (
discord.Guild
) – The guild to set a mod log channel for - channel (
discord.TextChannel
orNone
) – The channel to be set as modlog channel
Returns: True
if successfulReturn type: - guild (
-
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 forReturns: True
if successfulReturn type: bool