async def on_guild_emojis_update(self, guild, before, after): if not guild.me.guild_permissions.view_audit_log: return if ( LoggingEnum.NONE not in (options := self.get_enum(guild.id)) and (id := self.bot.cache[guild.id].get("logid")) is not None ): log_channel = guild.get_channel(id) entry = None if LoggingEnum.GUILD not in options or log_channel is None: return entry = await get_audit(guild, AuditLogAction.emoji_update) embed = CustomEmbed(title="Emojis Updated").add_field( name="Basic Info", value=(f"Moderator: {entry.user} [{entry.user.id}]\n"), ) embed.add_field( name="Advanced Info", value="\n".join( f"{title_format(diff[0])}: `{diff[1]}`" for diff in entry.after ), inline=False, ) embed.set_author(name=entry.user.name, icon_url=entry.user.avatar_url) with suppress(discord.Forbidden): await log_channel.send(embed=embed)
async def on_member_remove(self, member): if not member.guild.me.guild_permissions.view_audit_log: return if (LoggingEnum.NONE not in (options := self.bot.utils.get_enum( member.guild.id)) and (id := self.bot.cache[member.guild.id].get("logid")) is not None): if LoggingEnum.MODERATION not in options: return channel = self.bot.get_channel(id) if channel is None: return entry = await get_audit(member.guild, AuditLogAction.kick) if entry is None: return embed = CustomEmbed( title="**Member Kicked**", description=(f"User: {member} [{member.id}]\n" f"Moderator: {entry.user} [{entry.user.id}]" f"Reason: {getattr(entry, 'reason', 'None')}\n"), timestamp=datetime.utcnow(), ).set_thumbnail(url=member.avatar_url) embed.set_author(name=entry.user.name, url=entry.user.avatar_url) with suppress(discord.Forbidden): await channel.send(embed=embed)
async def on_member_unban(self, guild: discord.Guild, user: discord.User): if not guild.me.guild_permissions.view_audit_log: return if (LoggingEnum.NONE not in (options := self.bot.utils.get_enum( guild.id)) and (id := self.bot.cache[guild.id].get("logid")) is not None): if LoggingEnum.MODERATION not in options: return channel = self.bot.get_channel(id) if channel is None: return action = await get_audit(guild, AuditLogAction.unban) embed = CustomEmbed( title="**Member Unbanned**", description=(f"User: {user} [{user.id}]\n" f"Reason: {getattr(action, 'reason', 'None')}\n"), timestamp=datetime.utcnow(), ).set_thumbnail(url=user.avatar_url) if action: embed.description += f"Moderator: {action.user}" embed.set_author(name=action.user.name, url=action.user.avatar_url) with suppress(discord.Forbidden): await channel.send(embed=embed)
async def on_guild_role_create(self, role: discord.Role): guild = role.guild if not guild.me.guild_permissions.view_audit_log: return if ( LoggingEnum.NONE not in (options := self.get_enum(guild.id)) and (id := self.bot.cache[guild.id].get("logid")) is not None ): log_channel = guild.get_channel(id) entry = None if LoggingEnum.GUILD not in options or log_channel is None: return entry = await get_audit(guild, AuditLogAction.role_create) embed = CustomEmbed(title="Role Created").add_field( name="Basic Info", value=( f"Moderator: {entry.user} [{entry.user.id}]\n" f"Role: {role.name} [{role.id}]" ), ) embed.add_field( name="Advanced Info", value="\n".join( f"{title_format(diff[0])}: `{diff[1]}`" for diff in entry.after if diff[0] not in ("permissions", "permissions_new") ), inline=False, ) for diff in entry.after: if diff[0] in ("permissions"): embed.add_field( name=title_format(diff[0]), value=await self.bot.utils.paste( ( f"{role.name}\n" + "\n".join( f"{perm} : {value}" for perm, value in dict(diff[1]).items() ) ) ), ) embed.set_author(name=entry.user.name, icon_url=entry.user.avatar_url) with suppress(discord.Forbidden): await log_channel.send(embed=embed)
async def on_channel_update(self, before, after): guild = after.guild if not after.guild.me.guild_permissions.view_audit_log: return if (LoggingEnum.NONE not in (options := self.get_enum(guild.id)) and (id := self.bot.cache[guild.id].get("logid")) is not None): log_channel = guild.get_channel(id) if LoggingEnum.CHANNELS not in options or log_channel is None: return if guild.me.guild_permissions.view_audit_log: entry = (await guild.audit_logs( limit=1, action=AuditLogAction.channel_update).flatten())[0] embed = CustomEmbed(title="Channel Edited", timestamp=datetime.utcnow()) embed.add_field( name="Basic Info", value=(f"Channel: {after.mention} [{after.id}] \n" f"Moderator: {entry.user} [{entry.user.id}]\n"), ) embed.add_field( name="Advanced Info", value="\n".join([ title_format(diff[0] + f"`{diff[1]}`" for diff in entry.after if diff[0] != "overwrites") ]), ) for diff in entry.after: if diff[0] == "overwrites": embed.add_field( name="Overwrites", value=await self.bot.utils.paste(format_overwrites(diff[1])), ) embed.set_author(name=entry.user.name, url=entry.user.avatar_url) with suppress(discord.Forbidden): await log_channel.send(embed=embed)
async def guild_update(self, before: discord.Guild, after: discord.Guild): if not after.me.guild_permissions.view_audit_log: return if ( LoggingEnum.NONE not in (options := self.get_enum(after.id)) and (id := self.bot.cache[after.id].get("logid")) is not None ): log_channel = after.get_channel(id) if LoggingEnum.GUILD not in options or log_channel is None: return entry = await get_audit(after, AuditLogAction.guild_update) if entry is None: return embed = CustomEmbed(title="Guild Updated") embed.add_field( name="Basic Info", value=(f"Moderator: {entry.user} [{entry.user.id}]") ) embed.add_field( name="Advanced Info", value="\n".join( [f"{title_format(diff[0])}: `{diff[1]}`" for diff in entry.after] ), ) embed.set_author(name=entry.user.name, icon_url=entry.user.avatar_url) with suppress(discord.Forbidden): await log_channel.send(embed=embed)