35 lines
1.6 KiB
Python
35 lines
1.6 KiB
Python
import discord.commands
|
|
from discord.ext import commands
|
|
from configmanager import ConfigManager, LoggingManager
|
|
import datetime
|
|
|
|
memberlogs = int(ConfigManager.get()['Channels']['MemberLogs'])
|
|
|
|
class Moderation(commands.Cog, name='Moderation'):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.Cog.listener() # Join log
|
|
async def on_member_join(self, member):
|
|
channel = self.bot.get_channel(memberlogs)
|
|
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 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)
|
|
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 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)) |