Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import datetime
- class Events(commands.Cog):
- def __init__(self, client):
- self.client = client
- @commands.Cog.listener()
- async def on_message(self, message):
- if message.author == self.client.user:
- return
- bypass = discord.utils.get(message.guild.roles, name="*")
- if "discord.gg" in message.content.lower():
- if message.author == self.client.user:
- return
- if bypass in message.author.roles:
- return
- await message.delete()
- await message.channel.send("Advertising is forbidden")
- logs = discord.utils.get(message.guild.text_channels, name="logs")
- embed = discord.Embed(
- title='Advertisement',
- description=f"Advertising user: {message.author.mention} \n"
- f"Advertisement: {message.content}",
- color=discord.Colour.red(),
- timestamp=datetime.datetime.utcnow()
- )
- embed.set_thumbnail(url=message.author.avatar_url)
- await logs.send(embed=embed)
- @commands.Cog.listener()
- async def on_message_edit(self, before, after):
- bypass = discord.utils.get(after.guild.roles, name="*")
- if "discord.gg" in after.content.lower():
- if after.author == self.client.user:
- return
- if bypass in after.author.roles:
- return
- await after.delete()
- await after.channel.send("Advertising is forbidden")
- logs = discord.utils.get(after.guild.text_channels, name="logs")
- embed = discord.Embed(
- title='Advertisement',
- description=f"Advertising user: {after.author.mention} \n"
- f"Advertisement: {after.content}",
- color=discord.Colour.red(),
- timestamp=datetime.datetime.utcnow()
- )
- embed.set_thumbnail(url=after.author.avatar_url)
- await logs.send(embed=embed)
- def setup(client):
- client.add_cog(Events(client))
Add Comment
Please, Sign In to add comment