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
moderation.py
cogs/moderation.py
Raw Download
Find: Go to:
"""
Discord AI Bot - Moderation 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

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

    @commands.hybrid_command(name="kick", description="Kick a member")
    @commands.has_permissions(kick_members=True)
    async def kick(self, ctx, member: discord.Member, *, reason: str = None):
        if member == ctx.author:
            await ctx.send("❌ You cannot kick yourself.")
            return
        if member == ctx.guild.owner:
            await ctx.send("❌ You cannot kick the server owner.")
            return
        if member == self.bot.user:
            await ctx.send("❌ I cannot kick myself.")
            return
        if member.top_role >= ctx.author.top_role and ctx.author != ctx.guild.owner:
            await ctx.send("❌ You cannot kick someone with equal or higher roles.")
            return
        try:
            await member.kick(reason=reason)
            await ctx.send(f"✅ Kicked {member.mention}" + (f" | Reason: {reason}" if reason else ""))
        except discord.Forbidden:
            await ctx.send("❌ I don't have permission to kick members.")
        except Exception as e:
            await ctx.send(f"❌ An error occurred: {e}")

    @commands.hybrid_command(name="ban", description="Ban a member")
    @commands.has_permissions(ban_members=True)
    async def ban(self, ctx, member: discord.Member, *, reason: str = None):
        if member == ctx.author:
            await ctx.send("❌ You cannot ban yourself.")
            return
        if member == ctx.guild.owner:
            await ctx.send("❌ You cannot ban the server owner.")
            return
        if member == self.bot.user:
            await ctx.send("❌ I cannot ban myself.")
            return
        if member.top_role >= ctx.author.top_role and ctx.author != ctx.guild.owner:
            await ctx.send("❌ You cannot ban someone with equal or higher roles.")
            return
        try:
            await member.ban(reason=reason)
            await ctx.send(f"✅ Banned {member.mention}" + (f" | Reason: {reason}" if reason else ""))
        except discord.Forbidden:
            await ctx.send("❌ I don't have permission to ban members.")
        except Exception as e:
            await ctx.send(f"❌ An error occurred: {e}")

    @commands.hybrid_command(name="clear", description="Clear messages from a channel")
    @commands.has_permissions(manage_messages=True)
    async def clear(self, ctx, amount: int = 10):
        """Clear a specified number of messages (default: 10, max: 100)."""
        if amount < 1 or amount > 100:
            await ctx.send("❌ Please specify a number between 1 and 100.", delete_after=5)
            return
        
        try:
            deleted = await ctx.channel.purge(limit=amount + 1)  # +1 to include the command message
            await ctx.send(f"✅ Cleared {len(deleted) - 1} message(s).", delete_after=5)
        except discord.Forbidden:
            await ctx.send("❌ I don't have permission to delete messages in this channel.")
        except Exception as e:
            await ctx.send(f"❌ An error occurred: {e}")

async def setup(bot):
    await bot.add_cog(Moderation(bot))
81 lines•3.4 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