r4d1ants

Create a discord bot that has mod

Kodari AI
KodariAug 26 at 5:24 am 1
ModBot
A Discord moderation bot built with discord.py that provides essential moderation tools for server administrators. Features include kick, ban, mute, and warn commands with automatic logging to a designated channel. The bot tracks warning levels and can auto-mute or auto-ban users who exceed thresholds. Includes a configurable prefix, permission checks to restrict commands to moderators, and a help command listing all available moderation actions. Supports slash commands for modern Discord interactions and maintains an audit log of all moderation actions taken.
  1. Create a slash-command Discord moderation bot with permission and role-hierarchy checks.

  2. Add persistent warnings, moderation actions, error handling, and setup documentation.

Created a complete discord.py moderation bot with:

  • Slash commands: /kick, /ban, /unban, /timeout, /untimeout

  • Persistent /warn and /warnings storage

  • /clear, /slowmode, /lock, and /unlock

  • Permission and role-hierarchy checks

  • Bot permission error handling

  • .env token configuration

  • Development guild command syncing

  • README setup instructions

  • Dependency and Git ignore files

r4d1ants

How do I add it to my server

Kodari AI
KodariAug 26 at 5:25 am 1

To add the moderation bot to your server:

  1. Select your bot application.

  2. Open OAuth2 → URL Generator.

  3. Select these scopes:

    • bot

    • applications.commands

  4. Select bot permissions needed by the bot:

    • View Channels

    • Send Messages

    • Embed Links

    • Read Message History

    • Manage Messages

    • Manage Channels

    • Kick Members

    • Ban Members

    • Moderate Members

  5. Copy the generated URL, open it in your browser, select your server, and click Authorize.

You can also construct the invite URL manually:

Plain Text
https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot%20applications.commands&permissions=1099511638015

Replace YOUR_CLIENT_ID with the Application ID from General Information.

Then configure and run the bot locally:

Env
DISCORD_TOKEN=your_bot_token
GUILD_ID=your_server_id

Install dependencies and start it:

Shell
pip install -r requirements.txt
python bot.py

To copy your server ID, enable Developer Mode in Discord, right-click your server, and select Copy Server ID.

The bot’s role must remain below the members it needs to kick, ban, or moderate. Slash commands may appear immediately when GUILD_ID is configured; global commands can take longer to synchronize.

r4d1ants

Can’t I just give you my token and you add it

Kodari AI
KodariAug 26 at 5:31 am 1

No—don’t send me your Discord bot token. A token gives full control of the bot account, so it must remain private.

You need to add the bot yourself through the Developer Portal:

  1. Go to Developer Portal → Your Application → OAuth2 → URL Generator.

  2. Select bot and applications.commands.

  3. Choose the required permissions.

  4. Open the generated invite URL and authorize it for your server.

  5. Put the token only in your local .env file:

Env
DISCORD_TOKEN=your_token_here
GUILD_ID=your_server_id

If you already shared the token anywhere, immediately reset it under Developer Portal → Bot → Reset Token, then update your .env file.

r4d1ants

No dude I want to so you can add it I don’t want to do extra stuff

Kodari AI
KodariAug 26 at 5:31 am 1

I can’t accept or use your token, and a token alone cannot add a bot to a server. Discord requires a server owner or administrator to approve the bot through an OAuth2 invite.

The shortest safe option is:

  1. In the Developer Portal, open OAuth2 → URL Generator.

  2. Select bot and applications.commands.

  3. Copy the generated link and open it.

  4. Select your server and click Authorize.

You can then give me the bot’s Application ID—never its token—and I can help create the exact invite URL.

Kodari can make mistakes. Review important code before using.
Files
cogs
.gitignore
bot.py
README.md
requirements.txt
Code
6 391
bot.py
import logging
import os

import discord
from discord.ext import commands
from dotenv import load_dotenv

from cogs.moderation import Moderation


load_dotenv()

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
logger = logging.getLogger("moderation-bot")


class ModerationBot(commands.Bot):
    def __init__(self) -> None:
        intents = discord.Intents.default()
        intents.members = True

        super().__init__(
            command_prefix=commands.when_mentioned,
            intents=intents,
            help_command=None,
        )

    async def setup_hook(self) -> None:
        await self.add_cog(Moderation(self))

        dev_guild_id = os.getenv("DEV_GUILD_ID")
        if dev_guild_id:
            guild = discord.Object(id=int(dev_guild_id))
            self.tree.copy_global_to(guild=guild)
            await self.tree.sync(guild=guild)
            logger.info("Commands synced to development guild %s", dev_guild_id)
        else:
            await self.tree.sync()
            logger.info("Global commands synced")

    async def on_ready(self) -> None:
        if self.user:
            logger.info("Logged in as %s (%s)", self.user, self.user.id)

    async def on_app_command_error(
        self,
        interaction: discord.Interaction,
        error: discord.app_commands.AppCommandError,
    ) -> None:
        original = getattr(error, "original", error)

        if isinstance(original, discord.app_commands.errors.MissingPermissions):
            message = "You do not have permission to use this command."
        elif isinstance(original, discord.app_commands.errors.BotMissingPermissions):
            missing = ", ".join(original.missing_permissions).replace("_", " ")
            message = f"I am missing these permissions: {missing}."
        elif isinstance(original, discord.app_commands.errors.NoPrivateMessage):
            message = "This command can only be used inside a server."
        else:
            logger.error(
                "Unhandled application-command error",
                exc_info=(type(original), original, original.__traceback__),
            )
            message = "Something went wrong while running that command."

        if interaction.response.is_done():
            await interaction.followup.send(message, ephemeral=True)
        else:
            await interaction.response.send_message(message, ephemeral=True)


token = os.getenv("DISCORD_TOKEN")
if not token:
    raise RuntimeError("DISCORD_TOKEN is not set. Copy .env.example to .env and add your token.")

bot = ModerationBot()
bot.run(token)