help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
discord-ai-bot
/
cogs
RSK World
discord-ai-bot
Discord AI Bot - Python + discord.py + OpenAI API + AI Bot + Server Management + Moderation
cogs
  • __pycache__
  • __init__.py153 B
  • ai.py3.8 KB
  • automation.py2.2 KB
  • logging.py3.1 KB
  • management.py1.9 KB
  • moderation.py3.4 KB
logging.py
cogs/logging.py
Raw Download
Find: Go to:
"""
Discord AI Bot - Logging Features
Author: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277
Year: 2026
"""

import discord
from discord.ext import commands
from config import LOG_CHANNEL_ID

class Logging(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    async def get_log_channel(self, guild):
        if LOG_CHANNEL_ID:
            return self.bot.get_channel(LOG_CHANNEL_ID)
        # Fallback: find a channel named 'logs'
        return discord.utils.get(guild.text_channels, name="logs")

    @commands.Cog.listener()
    async def on_message_delete(self, message):
        if message.author.bot or not message.guild:
            return
        
        channel = await self.get_log_channel(message.guild)
        if channel:
            try:
                content = message.content if message.content else "*No text content (embed/sticker only)*"
                embed = discord.Embed(
                    title="Message Deleted",
                    description=f"**Author:** {message.author.mention}\n**Channel:** {message.channel.mention}\n**Content:** {content}",
                    color=discord.Color.orange(),
                    timestamp=message.created_at
                )
                embed.set_footer(text=f"User ID: {message.author.id}")
                await channel.send(embed=embed)
            except discord.Forbidden:
                pass  # Bot doesn't have permission to send messages
            except Exception:
                pass  # Silently fail to avoid errors

    @commands.Cog.listener()
    async def on_member_join(self, member):
        channel = await self.get_log_channel(member.guild)
        if channel:
            try:
                embed = discord.Embed(
                    title="Member Joined",
                    description=f"{member.mention} has joined the server.",
                    color=discord.Color.green(),
                    timestamp=member.joined_at
                )
                embed.set_thumbnail(url=member.display_avatar.url)
                await channel.send(embed=embed)
            except discord.Forbidden:
                pass  # Bot doesn't have permission to send messages
            except Exception:
                pass  # Silently fail to avoid errors

    @commands.Cog.listener()
    async def on_member_remove(self, member):
        channel = await self.get_log_channel(member.guild)
        if channel:
            try:
                embed = discord.Embed(
                    title="Member Left",
                    description=f"{member.mention} has left the server.",
                    color=discord.Color.red()
                )
                embed.set_thumbnail(url=member.display_avatar.url)
                await channel.send(embed=embed)
            except discord.Forbidden:
                pass  # Bot doesn't have permission to send messages
            except Exception:
                pass  # Silently fail to avoid errors

async def setup(bot):
    await bot.add_cog(Logging(bot))
83 lines•3.1 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer