add error handling to moderation

This commit is contained in:
Anya 2022-03-08 16:14:15 -08:00
parent 34f430e351
commit 1487fae885

View file

@ -1,10 +1,9 @@
import discord.commands
from discord.ext import commands
from configmanager import ConfigManager
from configmanager import ConfigManager, LoggingManager
import datetime
memberlogs = ConfigManager.get()['Channels']['MemberLogs']
print (memberlogs)
memberlogs = int(ConfigManager.get()['Channels']['MemberLogs'])
class Moderation(commands.Cog, name='Moderation'):
def __init__(self, bot):
@ -13,20 +12,24 @@ class Moderation(commands.Cog, name='Moderation'):
@commands.Cog.listener() # Join log
async def on_member_join(self, member):
channel = self.bot.get_channel(memberlogs)
if channel is not None:
try:
embed = discord.Embed(color=discord.Color.green(), description=f'{member.mention} | **Joined Discord**: {member.created_at.date()}', timestamp=datetime.datetime.now())
embed.set_author(name=f'{member} ({member.id})', icon_url=f'{member.display_avatar.url}?128')
embed.set_footer(text='User Left')
await member.guild.channel.send(embeds=[embed])
await channel.send(embeds=[embed])
except:
LoggingManager.log.error(f'Failed to send joinlog for {member} ({member.id}) in {channel}.')
@commands.Cog.listener() # Leave log
async def on_member_remove(self, member):
channel = self.bot.get_channel(memberlogs)
if channel is not None:
try:
embed = discord.Embed(color=discord.Color.red(), description=f'{member.mention} | **Joined Server**: {member.joined_at.date()}', timestamp=datetime.datetime.now())
embed.set_author(name=f'{member} ({member.id})', icon_url=f'{member.display_avatar.url}?128')
embed.set_footer(text='User Left')
await member.guild.channel.send(embeds=[embed])
await channel.send(embeds=[embed])
except:
LoggingManager.log.error(f'Failed to send leavelog for {member} ({member.id}) in {channel}.')
def setup(bot):
bot.add_cog(Moderation(bot))