async def on_member_remove(self, member): try: await member.guild.fetch_ban(member) except (discord.Forbidden, discord.NotFound): pass else: return ccp.event(f'{member} has left {member.guild}', event='MEMBER_REM') if member.bot: return cache = self.bot.guilds_ guild = member.guild if cache[guild.id]['goodbye_messages'] and ( chan := member.guild.get_channel( cache[guild.id]['system_channel'])): user = escape_markdown(str(member)) name = escape_markdown(member.display_name) server = escape_markdown(guild.name) msg = cache[guild.id]['goodbye_message'].replace( '@user', user).replace('@name', name).replace('@server', server) embed = Embed(description=msg, color=utils.Color.red) embed.set_author(name=member, icon_url=member.avatar_url) embed.set_footer(text='Leave', icon_url='attachment://unknown.png') embed.timestamp = datetime.datetime.utcnow() await chan.send(file=File('assets/leave.png', 'unknown.png'), embed=embed)
async def on_guild_join(self, guild): ccp.event(f'{guild} ({guild.owner})', event='GUILD_ADD') await self.bot.guilds_.insert(guild.id) if guild.system_channel: await self.bot.guilds_.update(guild.id, 'system_channel', guild.system_channel.id)
async def on_member_ban(self, guild, user): ccp.event(f'{user} was banned from {guild}', event='MEMBER_BAN') if user.bot: return if self.bot.members.get((user.id, guild.id)): await self.bot.members.delete((user.id, guild.id))
async def on_guild_remove(self, guild): ccp.event(f'{guild} ({guild.owner})', event='GUILD_REM') async with self.bot.pool.acquire() as con: await self.bot.guilds_.delete(guild.id) await con.execute('DELETE FROM members WHERE guild_id = $1', guild.id) await con.execute('DELETE FROM role_menus WHERE guild_id = $1', guild.id) await con.execute('DELETE FROM ranks WHERE guild_id = $1', guild.id)
async def on_member_join(self, member): ccp.event(f'{member} has joined {member.guild}', event='MEMBER_ADD') if member.bot: return cache = self.bot.guilds_ guild = member.guild if cache[guild.id]['welcome_messages'] and (chan := guild.get_channel( cache[guild.id]['system_channel'])): user = escape_markdown(str(member)) name = escape_markdown(member.display_name) server = escape_markdown(guild.name) msg = cache[guild.id]['welcome_message'].replace( '@user', user).replace('@name', name).replace('@server', server) embed = Embed(description=msg, color=utils.Color.green) embed.set_author(name=member, icon_url=member.avatar_url) embed.set_footer(text='Join', icon_url='attachment://unknown.png') embed.timestamp = datetime.datetime.utcnow() await chan.send(member.mention, file=File('assets/join.png', 'unknown.png'), embed=embed)
async def on_command(self, ctx): guild = ctx.guild if ctx.guild else 'dm' ccp.event( f'\u001b[1m{ctx.author}@{guild}\u001b[0m {repr(ctx.message.content)[1:-1]}', event='INVOKE')