g08e

i want to make an all in one discord bot like moderation autoroles reaction roles polls welcome and more

Kodari AI
KodariSep 2 at 10:03 am 1
AllInOneDiscordBot
A comprehensive Discord bot built with discord.py featuring moderation commands (kick, ban, mute, purge), automatic role assignment for new members, reaction-based role menus, interactive poll creation, customizable welcome messages, and additional utilities like server info, user info, and logging. The bot uses a modular cog structure for easy extensibility, includes a help command, and stores configuration data in JSON files for persistence.
  1. Create a secure discord.py bot entry point with environment-based configuration and extension loading.

  2. Add persistent JSON-backed guild settings and warnings.

  3. Implement moderation commands, autoroles, welcome messages, reaction roles, polls, and utility commands.

  4. Add dependency and secret-safe project configuration files.

Built an all-in-one discord.py bot with:

  • Moderation: kick, ban, timeout, purge, warn, warnings, clearwarnings

  • Autoroles: configure or disable automatic roles

  • Welcome system: configurable channel and message templates

  • Reaction roles: add, remove, and list role mappings

  • Polls: interactive button-based polls with vote tracking

  • Utility: ping, serverinfo, userinfo, and help

  • JSON persistence in data/settings.json

  • Prefix commands using ! and slash-command support

  • .env token configuration and logging

  • Permission and error handling

Setup:

Shell
pip install -r requirements.txt
cp .env.example .env

Add your bot token to .env:

Env
DISCORD_TOKEN=your_bot_token_here

Then start it:

Shell
python main.py

Enable the Server Members Intent and Message Content Intent in the Discord Developer Portal.

g08e

<redacted> is the token

Kodari AI
KodariSep 2 at 10:07 am 1

That bot token is now compromised because it was shared publicly. Immediately reset it:

  1. Select your application → Bot.

  2. Click Reset Token → confirm → copy the new token.

  3. Store it only in your local .env file:

Env
DISCORD_TOKEN=your_new_token_here

Never paste the token into chat, source code, GitHub, or screenshots. Ensure .env is listed in .gitignore.

g08e

wheres the .env filee

Kodari AI
KodariSep 2 at 10:07 am 1

The .env file should be in the project root, next to main.py:

Plain Text
AllInOneDiscordBot/
├── .env
├── .env.example
├── main.py
├── storage.py
└── cogs/

It isn’t created automatically because it must contain your private token. Create it by copying the example:

Windows:

Shell
copy .env.example .env

macOS/Linux:

Shell
cp .env.example .env

Then open .env and add the newly reset token:

Env
DISCORD_TOKEN=your_new_token_here

Do not use the token you previously pasted—it must be reset in the Discord Developer Portal.

g08e

wheres the .env filee

Kodari AI
KodariSep 2 at 10:08 am 1

There is no .env file yet—only .env.example. Create it in the same folder as main.py:

Plain Text
AllInOneDiscordBot/
├── main.py
├── .env.example
├── .env          ← create this
└── cogs/

Copy .env.example and rename the copy to .env, then add:

Env
DISCORD_TOKEN=your_new_reset_token_here

The file may be hidden because its name starts with .. Make sure File name extensions and Hidden items are enabled in Windows File Explorer. Do not use the token you previously shared; reset it first.

g08e

can u restart alll of this

Kodari AI
KodariSep 2 at 10:10 am 1

Yes. We can start from scratch with a clean, simple Discord bot setup.

Choose one:

  1. Clean rebuild — replace the current bot files with a fresh all-in-one bot.

  2. Minimal start — create only a basic bot first, then add moderation, autoroles, welcome messages, reaction roles, and polls step by step.

  3. Restart the running bot — keep the current files and simply run it again.

The token you shared must still be reset in the Discord Developer Portal before using the new setup.

g08e

clean rebuild

Kodari AI
KodariSep 2 at 10:11 am 1
  1. Replace the existing bot with a clean, minimal modular rebuild.

  2. Keep secrets in a new .env file created locally from .env.example.

  3. Re-add the core all-in-one features with simple setup instructions.

Clean rebuild reset:

  • Removed the old .env file so the exposed token is not stored.

  • Kept the modular bot structure with moderation, autoroles, welcome messages, reaction roles, polls, and utilities.

  • Added safer application-command error handling.

  • Added moderation hierarchy checks.

  • Updated .env.example with a safe placeholder.

Create your new .env file in the same folder as main.py:

Shell
cp .env.example .env

On Windows:

Shell
copy .env.example .env

Then add the newly reset token:

Env
DISCORD_TOKEN=your_new_token_here
TEST_GUILD_ID=

Install and start:

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

Enable Message Content Intent, Server Members Intent, and Reaction Intent in the Discord Developer Portal. Do not reuse the token previously posted.

Kodari can make mistakes. Review important code before using.
Files
cogs
.gitignore
main.py
requirements.txt
storage.py
Code
11 663
main.py
import logging
import os
from typing import Optional

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

from storage import Storage


load_dotenv()
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
)
logger = logging.getLogger("all_in_one_bot")


def get_prefix(_: commands.Bot, __: discord.Message) -> str:
    return commands.when_mentioned_or("!")(_, __)


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

        super().__init__(
            command_prefix=get_prefix,
            intents=intents,
            case_insensitive=True,
            help_command=None,
        )
        self.storage = Storage()

    async def setup_hook(self) -> None:
        extensions = (
            "cogs.moderation",
            "cogs.autoroles",
            "cogs.welcome",
            "cogs.reaction_roles",
            "cogs.polls",
            "cogs.utility",
        )
        for extension in extensions:
            await self.load_extension(extension)

        test_guild_id = os.getenv("TEST_GUILD_ID")
        if test_guild_id:
            guild = discord.Object(id=int(test_guild_id))
            self.tree.copy_global_to(guild=guild)
            await self.tree.sync(guild=guild)
            logger.info("Synced application commands to test guild %s", test_guild_id)
        else:
            await self.tree.sync()
            logger.info("Synced global application commands")


bot = AllInOneBot()


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


@bot.event
async def on_command_error(ctx: commands.Context, error: commands.CommandError) -> None:
    error = getattr(error, "original", error)

    if isinstance(error, commands.CommandNotFound):
        return
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("You do not have permission to use that command.", delete_after=8)
        return
    if isinstance(error, commands.BotMissingPermissions):
        await ctx.send("I am missing the permissions needed for that action.", delete_after=8)
        return
    if isinstance(error, commands.NoPrivateMessage):
        await ctx.send("That command can only be used in a server.", delete_after=8)
        return
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(f"Missing argument: `{error.param.name}`.", delete_after=8)
        return
    if isinstance(error, commands.BadArgument):
        await ctx.send("One or more arguments were invalid.", delete_after=8)
        return

    logger.exception("Unhandled command error", exc_info=error)
    await ctx.send("Something went wrong while running that command.", delete_after=8)


@bot.tree.error
async def on_app_command_error(
    interaction: discord.Interaction,
    error: discord.app_commands.AppCommandError,
) -> None:
    error = getattr(error, "original", error)
    if isinstance(error, discord.app_commands.MissingPermissions):
        message = "You do not have permission to use that command."
    elif isinstance(error, discord.app_commands.BotMissingPermissions):
        message = "I am missing the permissions needed for that action."
    elif isinstance(error, discord.app_commands.NoPrivateMessage):
        message = "That command can only be used in a server."
    else:
        logger.exception("Unhandled application command error", exc_info=error)
        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: Optional[str] = os.getenv("DISCORD_TOKEN")
if not token:
    raise RuntimeError("DISCORD_TOKEN is missing. Copy .env.example to .env and add your token.")

bot.run(token)