-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogging.py
40 lines (28 loc) · 1.21 KB
/
logging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from discord import TextChannel
from discord.ext import commands
from embed import footer_embed
class Logging(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.log_ch: TextChannel = self.bot.get_channel(int(os.getenv("MESSAGE_LOGS_CHANNEL")))
# Message Logging
@commands.Cog.listener()
async def on_message_delete(self, message):
emb = footer_embed(message, 'Message (Delete)', message.author.avatar_url)
# Avoid duplicate channel; i.e message delete from log channel
if message.channel == self.log_ch:
return
emb.add_field(name="Message", value=message.content)
await self.log_ch.send(embed=emb)
@commands.Cog.listener()
async def on_message_edit(self, before, after):
# If message data is malformed or blank, return
if (before.content == "") or (after.content == ""):
return
emb = footer_embed(after, 'Message (Edit)', before.author.avatar_url)
emb.add_field(name="Before", value=before.content, inline=False)
emb.add_field(name="After", value=after.content, inline=False)
await self.log_ch.send(embed=emb)
def setup(bot):
bot.add_cog(Logging(bot))