devsammc1.1

do you make discord bots?

Kodari AI
KodariJul 30 at 4:08 pm 1
DiscordCommunityBot
A customizable Discord bot built with discord.py for community management, moderation, utility commands, automated responses, embeds, role management, logging, and server-specific configuration. It securely loads credentials from environment variables, includes command error handling, and supports extensible features as the server grows.

β€”IYes Discord bots with build discord.py. Tell me the bot’s main features, commands, and whether it needs moderation, tickets, leveling, music, economy, or database support.

devsammc1.1

i need a discord bot that does tickets staff appications everything from messages in the discord server that say ip etc that stuff like this kinda but its called clover vanilla and its green not blue please make it have tickets and applications for staff and make it a welcome bot also make it also like a staff thing so i can time people out just does everything disord bots would do

2 images attached
Kodari AI
KodariJul 30 at 4:13 pm 10

I’ll create a green-themed Clover Vanilla Discord bot with tickets, staff applications, welcome messages, Minecraft information replies, moderation, logging, and secure environment-based configuration.

CloverVanillaBot
Clover Vanilla Bot is a green-themed Discord community bot for Minecraft servers. It provides persistent ticket panels with private support channels, staff applications with review controls, welcome and leave messages, configurable server information for IP, version, store, rules, and joining instructions, and automatic replies to common questions. It also includes timeout, warn, kick, ban, purge, lock, unlock, logging, help, user, and server utility commands. SQLite stores warnings, tickets, and applications while environment variables keep credentials and server settings secure.
devsammc1.1

is it setup?

Kodari AI
KodariJul 30 at 4:14 pm 1

Partially. The bot files were created, but it is not connected to Discord or running yet.

You still need to:

  1. Install dependencies:

    Shell
    pip install -r requirements.txt
    
  2. Copy .env.example to .env.

  3. Add your Discord bot token:

    Env
    DISCORD_TOKEN=your_bot_token_here
    
  4. Enable the required intents in the Discord Developer Portal:

    • Server Members Intent

    • Message Content Intent

  5. Invite the bot with the required permissions.

  6. Run it:

    Shell
    python bot.py
    

You’ll also need to configure your Clover Vanilla server’s IP, channels, roles, and application settings before everything works exactly for your server.

devsammc1.1

can i download the code so i can check it

Kodari AI
KodariJul 30 at 4:17 pm 1

Yes. Use the Download/Export project button in the project file panel to download the bot files.

The project should include:

  • bot.py

  • requirements.txt

  • .env.example

  • .gitignore

  • README.md

Before running it, rename .env.example to .env and add your Discord bot token. Never share the .env file publicly.

devsammc1.1

i dont see where

Kodari AI
KodariJul 30 at 4:17 pm 1

If you don’t see a Files, Project, or Download/Export panel, then this chat doesn’t currently provide a downloadable code package. I should clarify that my previous message overstated this.

I can still provide the complete bot source here, file by file, so you can copy it into a folder and run it. The required files are:

  • bot.py

  • requirements.txt

  • .env.example

  • .gitignore

  • README.md

I can also prepare the code in a format ready to copy into Replit, Visual Studio Code, or another hosting service.

devsammc1.1

copy it

Kodari AI
KodariJul 30 at 4:19 pm 9

Copy these files into the same folder.

bot.py

Python
import asyncio
import datetime
import logging
import os
import re
import sqlite3
import time
from typing import Optional

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

load_dotenv()

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

DATABASE_PATH = os.getenv("DATABASE_PATH", "clover_vanilla.db")
SERVER_NAME = os.getenv("SERVER_NAME", "Clover Vanilla")
SERVER_DESCRIPTION = os.getenv(
    "SERVER_DESCRIPTION",
    "A friendly Minecraft survival community.",
)
SERVER_IP = os.getenv("SERVER_IP", "play.example.net")
SERVER_VERSION = os.getenv("SERVER_VERSION", "Java Edition")
STORE_URL = os.getenv("STORE_URL", "https://example.com/store")
RULES_URL = os.getenv("RULES_URL", "https://example.com/rules")
DISCORD_INVITE = os.getenv("DISCORD_INVITE", "")
WELCOME_MESSAGE = os.getenv(
    "WELCOME_MESSAGE",
    "Welcome to Clover Vanilla! Please read the rules and enjoy your stay.",
)
AUTO_REPLY_COOLDOWN = int(os.getenv("AUTO_REPLY_COOLDOWN", "30"))

def env_int(name: str) -> Optional[int]:
    value = os.getenv(name, "").strip()
    if not value:
        return None

    try:
        return int(value)
    except ValueError:
        logger.warning("Invalid integer configured for %s", name)
        return None

SUPPORT_ROLE_ID = env_int("SUPPORT_ROLE_ID")
STAFF_ROLE_ID = env_int("STAFF_ROLE_ID") or SUPPORT_ROLE_ID
TICKET_CATEGORY_ID = env_int("TICKET_CATEGORY_ID")
APPLICATION_CATEGORY_ID = env_int("APPLICATION_CATEGORY_ID")
WELCOME_CHANNEL_ID = env_int("WELCOME_CHANNEL_ID")
LOG_CHANNEL_ID = env_int("LOG_CHANNEL_ID")
SYNC_GUILD_ID = env_int("SYNC_GUILD_ID")

GREEN = discord.Color.from_rgb(46, 204, 113)
DARK_GREEN = discord.Color.from_rgb(25, 135, 84)

intents = discord.Intents.default()
intents.members = True
intents.message_content = True

bot = commands.Bot(
    command_prefix="!",
    intents=intents,
    help_command=None,
    allowed_mentions=discord.AllowedMentions(
        everyone=False,
        roles=True,
        users=True,
    ),
)

def initialize_database() -> None:
    with sqlite3.connect(DATABASE_PATH) as connection:
        connection.executescript(
            """
            CREATE TABLE IF NOT EXISTS warnings (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                guild_id INTEGER NOT NULL,
                user_id INTEGER NOT NULL,
                moderator_id INTEGER NOT NULL,
                reason TEXT NOT NULL,
                created_at TEXT NOT NULL
            );

            CREATE TABLE IF NOT EXISTS tickets (
                channel_id INTEGER PRIMARY KEY,
                guild_id INTEGER NOT NULL,
                opener_id INTEGER NOT NULL,
                created_at TEXT NOT NULL
            );

            CREATE TABLE IF NOT EXISTS applications (
                channel_id INTEGER PRIMARY KEY,
                guild_id INTEGER NOT NULL,
                applicant_id INTEGER NOT NULL,
                status TEXT NOT NULL DEFAULT 'pending',
                created_at TEXT NOT NULL
            );
            """
        )

def database_execute(query: str, parameters: tuple = ()) -> None:
    with sqlite3.connect(DATABASE_PATH) as connection:
        connection.execute(query, parameters)
        connection.commit()

def database_fetchone(
    query: str,
    parameters: tuple = (),
) -> Optional[tuple]:
    with sqlite3.connect(DATABASE_PATH) as connection:
        return connection.execute(query, parameters).fetchone()

def database_fetchall(query: str, parameters: tuple = ()) -> list[tuple]:
    with sqlite3.connect(DATABASE_PATH) as connection:
        return connection.execute(query, parameters).fetchall()

def make_embed(
    title: str,
    description: str = "",
    color: discord.Color = GREEN,
) -> discord.Embed:
    embed = discord.Embed(
        title=title,
        description=description,
        color=color,
        timestamp=discord.utils.utcnow(),
    )
    embed.set_footer(text="Clover Vanilla")
    return embed

def get_configured_role(
    guild: discord.Guild,
    role_id: Optional[int],
) -> Optional[discord.Role]:
    if role_id is None:
        return None
    return guild.get_role(role_id)

def get_configured_category(
    guild: discord.Guild,
    category_id: Optional[int],
) -> Optional[discord.CategoryChannel]:
    if category_id is None:
        return None

    category = guild.get_channel(category_id)
    if isinstance(category, discord.CategoryChannel):
        return category

    return None

def is_staff(member: discord.Member) -> bool:
    if member.guild_permissions.administrator:
        return True

    if member.guild_permissions.manage_guild:
        return True

    staff_role = get_configured_role(member.guild, STAFF_ROLE_ID)
    return staff_role is not None and staff_role in member.roles

def has_moderation_permission(member: discord.Member) -> bool:
    return (
        member.guild_permissions.administrator
        or member.guild_permissions.moderate_members
    )

async def deny_if_not_staff(interaction: discord.Interaction) -> bool:
    if not isinstance(interaction.user, discord.Member) or not is_staff(
        interaction.user
    ):
        await interaction.response.send_message(
            "You need the configured staff role or Manage Server permission to use this.",
            ephemeral=True,
        )
        return True

    return False

async def send_log(
    guild: discord.Guild,
    title: str,
    description: str,
    color: discord.Color = GREEN,
) -> None:
    if LOG_CHANNEL_ID is None:
        return

    channel = guild.get_channel(LOG_CHANNEL_ID)

    if isinstance(channel, discord.TextChannel):
        try:
            await channel.send(embed=make_embed(title, description, color))
        except discord.HTTPException:
            logger.exception("Unable to send a log message")

async def safely_dm(
    user: discord.abc.User,
    message: str,
) -> None:
    try:
        await user.send(message)
    except (discord.Forbidden, discord.HTTPException):
        pass

def clean_channel_name(value: str) -> str:
    cleaned = re.sub(r"[^a-zA-Z0-9-]", "-", value.lower())
    cleaned = re.sub(r"-+", "-", cleaned).strip("-")
    return cleaned[:40] or "user"

def get_server_info_embed() -> discord.Embed:
    embed = make_embed(
        f"{SERVER_NAME} | Server Information",
        SERVER_DESCRIPTION,
    )

    embed.add_field(
        name="Server IP",
        value=f"`{SERVER_IP}`",
        inline=False,
    )
    embed.add_field(
        name="Version",
        value=SERVER_VERSION,
        inline=True,
    )
    embed.add_field(
        name="Store",
        value=f"[Open store]({STORE_URL})",
        inline=True,
    )
    embed.add_field(
        name="Rules",
        value=f"[Read rules]({RULES_URL})",
        inline=True,
    )

    if DISCORD_INVITE:
        embed.add_field(
            name="Invite",
            value=f"[Join the Discord]({DISCORD_INVITE})",
            inline=False,
        )

    return embed

def get_join_embed() -> discord.Embed:
    embed = make_embed(
        "How to Join Clover Vanilla",
        "Follow these steps to join the Minecraft server.",
    )

    embed.add_field(
        name="Java Edition",
        value=(
            "1. Open Minecraft Java Edition.\n"
            "2. Select **Multiplayer**.\n"
            "3. Select **Add Server**.\n"
            f"4. Enter `{SERVER_IP}` as the server address.\n"
            "5. Select **Done**, then join the server."
        ),
        inline=False,
    )

    embed.add_field(
        name="Bedrock Edition",
        value=(
            "Use the Bedrock address and port configured by the server owner. "
            "Ask staff if you need connection details."
        ),
        inline=False,
    )

    return embed

class TicketCloseView(discord.ui.View):
    def __init__(self) -> None:
        super().__init__(timeout=None)

    @discord.ui.button(
        label="Close Ticket",
        style=discord.ButtonStyle.danger,
        emoji="πŸ”’",
        custom_id="clover_ticket_close",
    )
    async def close_ticket(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        if not isinstance(interaction.channel, discord.TextChannel):
            await interaction.response.send_message(
                "This button can only be used inside a ticket.",
                ephemeral=True,
            )
            return

        record = database_fetchone(
            """
            SELECT opener_id FROM tickets
            WHERE channel_id = ? AND guild_id = ?
            """,
            (interaction.channel.id, interaction.guild_id),
        )

        if record is None:
            await interaction.response.send_message(
                "This channel is not registered as an active ticket.",
                ephemeral=True,
            )
            return

        is_opener = interaction.user.id == record[0]
        is_authorized_staff = (
            isinstance(interaction.user, discord.Member)
            and is_staff(interaction.user)
        )

        if not is_opener and not is_authorized_staff:
            await interaction.response.send_message(
                "Only the ticket opener or staff can close this ticket.",
                ephemeral=True,
            )
            return

        await interaction.response.send_message(
            "This ticket will be closed in a few seconds.",
            ephemeral=True,
        )

        await send_log(
            interaction.guild,
            "Ticket Closed",
            f"{interaction.channel.mention} was closed by {interaction.user.mention}.",
        )

        database_execute(
            "DELETE FROM tickets WHERE channel_id = ?",
            (interaction.channel.id,),
        )

        await asyncio.sleep(3)

        try:
            await interaction.channel.delete(reason="Ticket closed")
        except discord.HTTPException:
            pass

class TicketPanelView(discord.ui.View):
    def __init__(self) -> None:
        super().__init__(timeout=None)

    @discord.ui.button(
        label="Create Ticket",
        style=discord.ButtonStyle.success,
        emoji="🎫",
        custom_id="clover_ticket_create",
    )
    async def create_ticket(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        if interaction.guild is None or not isinstance(
            interaction.user,
            discord.Member,
        ):
            await interaction.response.send_message(
                "Tickets can only be created inside a server.",
                ephemeral=True,
            )
            return

        existing = database_fetchone(
            """
            SELECT channel_id FROM tickets
            WHERE guild_id = ? AND opener_id = ?
            """,
            (interaction.guild.id, interaction.user.id),
        )

        if existing is not None:
            existing_channel = interaction.guild.get_channel(existing[0])

            if existing_channel is not None:
                await interaction.response.send_message(
                    f"You already have an open ticket: {existing_channel.mention}",
                    ephemeral=True,
                )
                return

            database_execute(
                "DELETE FROM tickets WHERE channel_id = ?",
                (existing[0],),
            )

        category = get_configured_category(
            interaction.guild,
            TICKET_CATEGORY_ID,
        )

        support_role = get_configured_role(
            interaction.guild,
            SUPPORT_ROLE_ID,
        )

        overwrites = {
            interaction.guild.default_role: discord.PermissionOverwrite(
                view_channel=False,
            ),
            interaction.user: discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
                attach_files=True,
            ),
        }

        if interaction.guild.me is not None:
            overwrites[interaction.guild.me] = discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
                manage_channels=True,
            )

        if support_role is not None:
            overwrites[support_role] = discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
            )

        try:
            channel = await interaction.guild.create_text_channel(
                name=f"ticket-{clean_channel_name(interaction.user.display_name)}",
                category=category,
                overwrites=overwrites,
                topic=(
                    f"Clover Vanilla ticket opened by "
                    f"{interaction.user} ({interaction.user.id})"
                ),
                reason="New support ticket",
            )

            database_execute(
                """
                INSERT INTO tickets (channel_id, guild_id, opener_id, created_at)
                VALUES (?, ?, ?, ?)
                """,
                (
                    channel.id,
                    interaction.guild.id,
                    interaction.user.id,
                    discord.utils.utcnow().isoformat(),
                ),
            )

            staff_mention = (
                support_role.mention
                if support_role
                else "the staff team"
            )

            embed = make_embed(
                "Support Ticket",
                (
                    f"Welcome {interaction.user.mention}!\n\n"
                    f"{staff_mention} will help you as soon as possible. "
                    "Please explain your issue and include any useful details."
                ),
            )

            await channel.send(
                content=interaction.user.mention,
                embed=embed,
                view=TicketCloseView(),
            )

            await interaction.response.send_message(
                f"Your ticket has been created: {channel.mention}",
                ephemeral=True,
            )

            await send_log(
                interaction.guild,
                "Ticket Created",
                f"{channel.mention} was opened by {interaction.user.mention}.",
            )

        except discord.Forbidden:
            await interaction.response.send_message(
                "I do not have permission to create ticket channels.",
                ephemeral=True,
            )
        except discord.HTTPException:
            logger.exception("Unable to create ticket")
            await interaction.response.send_message(
                "The ticket could not be created. Please contact staff.",
                ephemeral=True,
            )

class StaffApplicationModal(
    discord.ui.Modal,
    title="Clover Vanilla Staff Application",
):
    age = discord.ui.TextInput(
        label="How old are you?",
        placeholder="Your age",
        max_length=3,
        required=True,
    )

    timezone = discord.ui.TextInput(
        label="What is your timezone?",
        placeholder="For example: GMT, EST, or CET",
        max_length=80,
        required=True,
    )

    experience = discord.ui.TextInput(
        label="What staff experience do you have?",
        placeholder=(
            "Tell us about previous moderation or administration experience."
        ),
        style=discord.TextStyle.paragraph,
        max_length=1000,
        required=True,
    )

    motivation = discord.ui.TextInput(
        label="Why should we choose you?",
        placeholder=(
            "Tell us why you want to join the Clover Vanilla staff team."
        ),
        style=discord.TextStyle.paragraph,
        max_length=1500,
        required=True,
    )

    availability = discord.ui.TextInput(
        label="How active can you be?",
        placeholder="Describe your usual weekly availability.",
        style=discord.TextStyle.paragraph,
        max_length=1000,
        required=True,
    )

    async def on_submit(
        self,
        interaction: discord.Interaction,
    ) -> None:
        if interaction.guild is None or not isinstance(
            interaction.user,
            discord.Member,
        ):
            await interaction.response.send_message(
                "Applications can only be submitted inside a server.",
                ephemeral=True,
            )
            return

        existing = database_fetchone(
            """
            SELECT channel_id FROM applications
            WHERE guild_id = ? AND applicant_id = ? AND status = 'pending'
            """,
            (interaction.guild.id, interaction.user.id),
        )

        if existing is not None:
            existing_channel = interaction.guild.get_channel(existing[0])

            if existing_channel is not None:
                await interaction.response.send_message(
                    f"You already have a pending application: {existing_channel.mention}",
                    ephemeral=True,
                )
                return

            database_execute(
                "DELETE FROM applications WHERE channel_id = ?",
                (existing[0],),
            )

        category = get_configured_category(
            interaction.guild,
            APPLICATION_CATEGORY_ID,
        )

        staff_role = get_configured_role(
            interaction.guild,
            STAFF_ROLE_ID,
        )

        overwrites = {
            interaction.guild.default_role: discord.PermissionOverwrite(
                view_channel=False,
            ),
            interaction.user: discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
            ),
        }

        if interaction.guild.me is not None:
            overwrites[interaction.guild.me] = discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
                manage_channels=True,
            )

        if staff_role is not None:
            overwrites[staff_role] = discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
            )

        try:
            channel = await interaction.guild.create_text_channel(
                name=(
                    f"application-"
                    f"{clean_channel_name(interaction.user.display_name)}"
                ),
                category=category,
                overwrites=overwrites,
                topic=(
                    f"Staff application submitted by "
                    f"{interaction.user} ({interaction.user.id})"
                ),
                reason="New staff application",
            )

            database_execute(
                """
                INSERT INTO applications
                (channel_id, guild_id, applicant_id, status, created_at)
                VALUES (?, ?, ?, 'pending', ?)
                """,
                (
                    channel.id,
                    interaction.guild.id,
                    interaction.user.id,
                    discord.utils.utcnow().isoformat(),
                ),
            )

            embed = make_embed(
                "New Staff Application",
                f"Applicant: {interaction.user.mention}\n"
                "Status: **Pending Review**",
            )

            embed.add_field(
                name="Age",
                value=str(self.age),
                inline=True,
            )
            embed.add_field(
                name="Timezone",
                value=str(self.timezone),
                inline=True,
            )
            embed.add_field(
                name="Availability",
                value=str(self.availability),
                inline=False,
            )
            embed.add_field(
                name="Staff Experience",
                value=str(self.experience),
                inline=False,
            )
            embed.add_field(
                name="Motivation",
                value=str(self.motivation),
                inline=False,
            )

            await channel.send(
                content=staff_role.mention if staff_role else None,
                embed=embed,
                view=ApplicationReviewView(),
            )

            await interaction.response.send_message(
                f"Your application has been submitted: {channel.mention}",
                ephemeral=True,
            )

            await send_log(
                interaction.guild,
                "Staff Application Submitted",
                f"{interaction.user.mention} submitted {channel.mention}.",
            )

        except discord.Forbidden:
            await interaction.response.send_message(
                "I do not have permission to create application channels.",
                ephemeral=True,
            )
        except discord.HTTPException:
            logger.exception("Unable to create staff application")
            await interaction.response.send_message(
                "The application could not be submitted. Please contact staff.",
                ephemeral=True,
            )

class ApplicationPanelView(discord.ui.View):
    def __init__(self) -> None:
        super().__init__(timeout=None)

    @discord.ui.button(
        label="Apply for Staff",
        style=discord.ButtonStyle.success,
        emoji="πŸ“",
        custom_id="clover_application_create",
    )
    async def apply_for_staff(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        await interaction.response.send_modal(StaffApplicationModal())

class ApplicationReviewView(discord.ui.View):
    def __init__(self) -> None:
        super().__init__(timeout=None)

    @discord.ui.button(
        label="Approve",
        style=discord.ButtonStyle.success,
        emoji="βœ…",
        custom_id="clover_application_approve",
    )
    async def approve(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        if await deny_if_not_staff(interaction):
            return

        if interaction.guild is None or not isinstance(
            interaction.channel,
            discord.TextChannel,
        ):
            return

        record = database_fetchone(
            """
            SELECT applicant_id, status FROM applications
            WHERE channel_id = ? AND guild_id = ?
            """,
            (interaction.channel.id, interaction.guild.id),
        )

        if record is None:
            await interaction.response.send_message(
                "This is not a registered application channel.",
                ephemeral=True,
            )
            return

        if record[1] != "pending":
            await interaction.response.send_message(
                f"This application has already been {record[1]}.",
                ephemeral=True,
            )
            return

        database_execute(
            """
            UPDATE applications SET status = 'approved'
            WHERE channel_id = ?
            """,
            (interaction.channel.id,),
        )

        applicant = interaction.guild.get_member(record[0])

        if applicant is not None:
            await safely_dm(
                applicant,
                (
                    f"Your Clover Vanilla staff application in "
                    f"{interaction.guild.name} was approved!"
                ),
            )

        await interaction.response.send_message(
            f"Application approved by {interaction.user.mention}.",
        )

        await send_log(
            interaction.guild,
            "Staff Application Approved",
            (
                f"{interaction.channel.mention} was approved by "
                f"{interaction.user.mention}."
            ),
        )

    @discord.ui.button(
        label="Deny",
        style=discord.ButtonStyle.danger,
        emoji="❌",
        custom_id="clover_application_deny",
    )
    async def deny(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        if await deny_if_not_staff(interaction):
            return

        if interaction.guild is None or not isinstance(
            interaction.channel,
            discord.TextChannel,
        ):
            return

        record = database_fetchone(
            """
            SELECT applicant_id, status FROM applications
            WHERE channel_id = ? AND guild_id = ?
            """,
            (interaction.channel.id, interaction.guild.id),
        )

        if record is None:
            await interaction.response.send_message(
                "This is not a registered application channel.",
                ephemeral=True,
            )
            return

        if record[1] != "pending":
            await interaction.response.send_message(
                f"This application has already been {record[1]}.",
                ephemeral=True,
            )
            return

        database_execute(
            """
            UPDATE applications SET status = 'denied'
            WHERE channel_id = ?
            """,
            (interaction.channel.id,),
        )

        applicant = interaction.guild.get_member(record[0])

        if applicant is not None:
            await safely_dm(
                applicant,
                (
                    f"Your Clover Vanilla staff application in "
                    f"{interaction.guild.name} was not accepted this time."
                ),
            )

        await interaction.response.send_message(
            f"Application denied by {interaction.user.mention}.",
        )

        await send_log(
            interaction.guild,
            "Staff Application Denied",
            (
                f"{interaction.channel.mention} was denied by "
                f"{interaction.user.mention}."
            ),
            discord.Color.red(),
        )

    @discord.ui.button(
        label="Close Application",
        style=discord.ButtonStyle.secondary,
        emoji="πŸ”’",
        custom_id="clover_application_close",
    )
    async def close_application(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        if await deny_if_not_staff(interaction):
            return

        if not isinstance(interaction.channel, discord.TextChannel):
            return

        database_execute(
            "DELETE FROM applications WHERE channel_id = ?",
            (interaction.channel.id,),
        )

        await interaction.response.send_message(
            "This application channel will be closed in a few seconds.",
            ephemeral=True,
        )

        await send_log(
            interaction.guild,
            "Application Closed",
            (
                f"{interaction.channel.mention} was closed by "
                f"{interaction.user.mention}."
            ),
        )

        await asyncio.sleep(3)

        try:
            await interaction.channel.delete(
                reason="Staff application closed",
            )
        except discord.HTTPException:
            pass

setup_group = app_commands.Group(
    name="setup",
    description="Create Clover Vanilla panels and server information messages.",
)

@setup_group.command(
    name="tickets",
    description="Post the green support ticket panel.",
)
async def setup_tickets(interaction: discord.Interaction) -> None:
    if interaction.guild is None or not isinstance(
        interaction.user,
        discord.Member,
    ):
        await interaction.response.send_message(
            "This command can only be used inside a server.",
            ephemeral=True,
        )
        return

    if not interaction.user.guild_permissions.manage_guild:
        await interaction.response.send_message(
            "You need Manage Server permission to use this.",
            ephemeral=True,
        )
        return

    embed = make_embed(
        "Clover Vanilla Support",
        (
            "Need help, want to report a player, or have a purchase issue?\n\n"
            "Click the button below to open a private ticket with the staff team."
        ),
    )

    await interaction.channel.send(
        embed=embed,
        view=TicketPanelView(),
    )

    await interaction.response.send_message(
        "The ticket panel has been posted.",
        ephemeral=True,
    )

@setup_group.command(
    name="applications",
    description="Post the staff application panel.",
)
async def setup_applications(interaction: discord.Interaction) -> None:
    if interaction.guild is None or not isinstance(
        interaction.user,
        discord.Member,
    ):
        await interaction.response.send_message(
            "This command can only be used inside a server.",
            ephemeral=True,
        )
        return

    if not interaction.user.guild_permissions.manage_guild:
        await interaction.response.send_message(
            "You need Manage Server permission to use this.",
            ephemeral=True,
        )
        return

    embed = make_embed(
        "Clover Vanilla Staff Applications",
        (
            "Interested in helping the community? Click the button below "
            "to complete the staff application form.\n\n"
            "Please answer every question honestly and in detail."
        ),
    )

    await interaction.channel.send(
        embed=embed,
        view=ApplicationPanelView(),
    )

    await interaction.response.send_message(
        "The staff application panel has been posted.",
        ephemeral=True,
    )

@setup_group.command(
    name="information",
    description="Post the Minecraft server information panel.",
)
async def setup_information(interaction: discord.Interaction) -> None:
    if interaction.guild is None or not isinstance(
        interaction.user,
        discord.Member,
    ):
        await interaction.response.send_message(
            "This command can only be used inside a server.",
            ephemeral=True,
        )
        return

    if not interaction.user.guild_permissions.manage_guild:
        await interaction.response.send_message(
            "You need Manage Server permission to use this.",
            ephemeral=True,
        )
        return

    await interaction.channel.send(
        embeds=[
            get_server_info_embed(),
            get_join_embed(),
        ],
    )

    await interaction.response.send_message(
        "The server information panels have been posted.",
        ephemeral=True,
    )

bot.tree.add_command(setup_group)

@bot.tree.command(
    name="ping",
    description="Check whether Clover Vanilla Bot is online.",
)
async def ping(interaction: discord.Interaction) -> None:
    latency = round(bot.latency * 1000)

    await interaction.response.send_message(
        embed=make_embed(
            "Pong!",
            (
                "Clover Vanilla Bot is online with "
                f"`{latency}ms` latency."
            ),
        ),
        ephemeral=True,
    )

@bot.tree.command(
    name="info",
    description="Show Clover Vanilla server information.",
)
async def info(interaction: discord.Interaction) -> None:
    await interaction.response.send_message(
        embed=get_server_info_embed(),
    )

@bot.tree.command(
    name="join",
    description="Show instructions for joining the Minecraft server.",
)
async def join(interaction: discord.Interaction) -> None:
    await interaction.response.send_message(
        embed=get_join_embed(),
    )

@bot.tree.command(
    name="help",
    description="Show the bot's available commands.",
)
async def help_command(interaction: discord.Interaction) -> None:
    embed = make_embed(
        "Clover Vanilla Bot Commands",
        "Here are the commands available to members and staff.",
    )

    embed.add_field(
        name="Members",
        value=(
            "`/info` β€” Minecraft server information\n"
            "`/join` β€” How to join\n"
            "`/ping` β€” Bot latency\n"
            "Use the ticket and application panels posted by staff."
        ),
        inline=False,
    )

    embed.add_field(
        name="Staff",
        value=(
            "`/timeout` `/untimeout` `/warn` `/warnings`\n"
            "`/kick` `/ban` `/purge` `/lock` `/unlock`\n"
            "`/setup tickets` `/setup applications` "
            "`/setup information`"
        ),
        inline=False,
    )

    await interaction.response.send_message(
        embed=embed,
        ephemeral=True,
    )

@bot.tree.command(
    name="userinfo",
    description="Show information about a server member.",
)
@app_commands.describe(member="The member to inspect.")
async def userinfo(
    interaction: discord.Interaction,
    member: Optional[discord.Member] = None,
) -> None:
    target = member or interaction.user

    embed = make_embed(
        f"User Information: {target.display_name}",
    )
    embed.set_thumbnail(url=target.display_avatar.url)

    embed.add_field(
        name="Username",
        value=str(target),
        inline=True,
    )
    embed.add_field(
        name="User ID",
        value=str(target.id),
        inline=True,
    )
    embed.add_field(
        name="Joined Server",
        value=(
            discord.utils.format_dt(target.joined_at, "F")
            if target.joined_at
            else "Unknown"
        ),
        inline=False,
    )

    roles = [role.mention for role in target.roles[1:]]

    embed.add_field(
        name="Roles",
        value=", ".join(roles[-10:]) if roles else "No roles",
        inline=False,
    )

    await interaction.response.send_message(
        embed=embed,
    )

@bot.tree.command(
    name="serverinfo",
    description="Show information about this Discord server.",
)
async def serverinfo(interaction: discord.Interaction) -> None:
    if interaction.guild is None:
        await interaction.response.send_message(
            "This is only available in a server.",
            ephemeral=True,
        )
        return

    guild = interaction.guild

    embed = make_embed(
        f"Discord Server: {guild.name}",
    )

    if guild.icon:
        embed.set_thumbnail(url=guild.icon.url)

    embed.add_field(
        name="Members",
        value=str(guild.member_count),
        inline=True,
    )
    embed.add_field(
        name="Channels",
        value=str(len(guild.channels)),
        inline=True,
    )
    embed.add_field(
        name="Roles",
        value=str(len(guild.roles)),
        inline=True,
    )
    embed.add_field(
        name="Created",
        value=discord.utils.format_dt(guild.created_at, "F"),
        inline=False,
    )

    await interaction.response.send_message(
        embed=embed,
    )

@bot.tree.command(
    name="timeout",
    description="Timeout a member.",
)
@app_commands.describe(
    member="The member to timeout.",
    minutes="Timeout duration in minutes.",
    reason="Reason for the timeout.",
)
async def timeout_member(
    interaction: discord.Interaction,
    member: discord.Member,
    minutes: app_commands.Range[int, 1, 40320],
    reason: Optional[str] = None,
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not has_moderation_permission(interaction.user)
    ):
        await interaction.response.send_message(
            "You need Moderate Members permission to use this.",
            ephemeral=True,
        )
        return

    if member == interaction.user or member == interaction.guild.owner:
        await interaction.response.send_message(
            "You cannot timeout that member.",
            ephemeral=True,
        )
        return

    if (
        interaction.user.top_role <= member.top_role
        and not interaction.user.guild_permissions.administrator
    ):
        await interaction.response.send_message(
            "That member has an equal or higher role than you.",
            ephemeral=True,
        )
        return

    reason = reason or "No reason provided"

    try:
        await member.timeout(
            datetime.timedelta(minutes=minutes),
            reason=reason,
        )

        await interaction.response.send_message(
            embed=make_embed(
                "Member Timed Out",
                (
                    f"{member.mention} was timed out for "
                    f"**{minutes} minutes**.\nReason: {reason}"
                ),
            ),
        )

        await safely_dm(
            member,
            (
                f"You were timed out in {interaction.guild.name} "
                f"for {minutes} minutes.\nReason: {reason}"
            ),
        )

        await send_log(
            interaction.guild,
            "Member Timed Out",
            (
                f"{member.mention} was timed out by "
                f"{interaction.user.mention}.\nReason: {reason}"
            ),
        )

    except discord.Forbidden:
        await interaction.response.send_message(
            "I cannot timeout that member. Check my role position and permissions.",
            ephemeral=True,
        )

@bot.tree.command(
    name="untimeout",
    description="Remove a member's timeout.",
)
@app_commands.describe(
    member="The member to untimeout.",
    reason="Reason for removing the timeout.",
)
async def untimeout_member(
    interaction: discord.Interaction,
    member: discord.Member,
    reason: Optional[str] = None,
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not has_moderation_permission(interaction.user)
    ):
        await interaction.response.send_message(
            "You need Moderate Members permission to use this.",
            ephemeral=True,
        )
        return

    try:
        await member.timeout(
            None,
            reason=reason or "No reason provided",
        )

        await interaction.response.send_message(
            f"{member.mention} is no longer timed out.",
        )

        await send_log(
            interaction.guild,
            "Timeout Removed",
            (
                f"{member.mention} was un-timed out by "
                f"{interaction.user.mention}."
            ),
        )

    except discord.Forbidden:
        await interaction.response.send_message(
            "I cannot remove that timeout. Check my role position and permissions.",
            ephemeral=True,
        )

@bot.tree.command(
    name="warn",
    description="Warn a member and save it to the database.",
)
@app_commands.describe(
    member="The member to warn.",
    reason="Reason for the warning.",
)
async def warn_member(
    interaction: discord.Interaction,
    member: discord.Member,
    reason: str,
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not has_moderation_permission(interaction.user)
    ):
        await interaction.response.send_message(
            "You need Moderate Members permission to use this.",
            ephemeral=True,
        )
        return

    if member.bot:
        await interaction.response.send_message(
            "Bots cannot be warned.",
            ephemeral=True,
        )
        return

    database_execute(
        """
        INSERT INTO warnings
        (guild_id, user_id, moderator_id, reason, created_at)
        VALUES (?, ?, ?, ?, ?)
        """,
        (
            interaction.guild.id,
            member.id,
            interaction.user.id,
            reason,
            discord.utils.utcnow().isoformat(),
        ),
    )

    await interaction.response.send_message(
        embed=make_embed(
            "Warning Issued",
            f"{member.mention} has been warned.\nReason: {reason}",
            discord.Color.orange(),
        ),
    )

    await safely_dm(
        member,
        (
            f"You received a warning in {interaction.guild.name}.\n"
            f"Reason: {reason}"
        ),
    )

    await send_log(
        interaction.guild,
        "Member Warned",
        (
            f"{member.mention} was warned by "
            f"{interaction.user.mention}.\nReason: {reason}"
        ),
        discord.Color.orange(),
    )

@bot.tree.command(
    name="warnings",
    description="View a member's saved warnings.",
)
@app_commands.describe(
    member="The member whose warnings should be shown.",
)
async def warnings(
    interaction: discord.Interaction,
    member: discord.Member,
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not is_staff(interaction.user)
    ):
        await interaction.response.send_message(
            "You need the configured staff role or Manage Server permission to use this.",
            ephemeral=True,
        )
        return

    records = database_fetchall(
        """
        SELECT reason, moderator_id, created_at FROM warnings
        WHERE guild_id = ? AND user_id = ?
        ORDER BY id DESC LIMIT 10
        """,
        (interaction.guild.id, member.id),
    )

    embed = make_embed(
        f"Warnings: {member}",
        f"Showing the latest {len(records)} warning(s).",
    )

    if not records:
        embed.description = f"{member.mention} has no saved warnings."

    for index, record in enumerate(records, 1):
        moderator = interaction.guild.get_member(record[1])
        moderator_name = moderator.mention if moderator else str(record[1])

        embed.add_field(
            name=f"Warning {index}",
            value=f"{record[0]}\nModerator: {moderator_name}",
            inline=False,
        )

    await interaction.response.send_message(
        embed=embed,
        ephemeral=True,
    )

@bot.tree.command(
    name="kick",
    description="Kick a member from the server.",
)
@app_commands.describe(
    member="The member to kick.",
    reason="Reason for the kick.",
)
async def kick_member(
    interaction: discord.Interaction,
    member: discord.Member,
    reason: Optional[str] = None,
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not interaction.user.guild_permissions.kick_members
    ):
        await interaction.response.send_message(
            "You need Kick Members permission to use this.",
            ephemeral=True,
        )
        return

    if member == interaction.guild.owner or (
        interaction.user.top_role <= member.top_role
        and not interaction.user.guild_permissions.administrator
    ):
        await interaction.response.send_message(
            "You cannot kick that member.",
            ephemeral=True,
        )
        return

    reason = reason or "No reason provided"

    await safely_dm(
        member,
        f"You were kicked from {interaction.guild.name}.\nReason: {reason}",
    )

    try:
        await member.kick(reason=reason)

        await interaction.response.send_message(
            f"{member} was kicked. Reason: {reason}",
        )

        await send_log(
            interaction.guild,
            "Member Kicked",
            (
                f"{member} was kicked by "
                f"{interaction.user.mention}.\nReason: {reason}"
            ),
            discord.Color.orange(),
        )

    except discord.Forbidden:
        await interaction.response.send_message(
            "I cannot kick that member. Check my role position and permissions.",
            ephemeral=True,
        )

@bot.tree.command(
    name="ban",
    description="Ban a member from the server.",
)
@app_commands.describe(
    member="The member to ban.",
    reason="Reason for the ban.",
)
async def ban_member(
    interaction: discord.Interaction,
    member: discord.Member,
    reason: Optional[str] = None,
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not interaction.user.guild_permissions.ban_members
    ):
        await interaction.response.send_message(
            "You need Ban Members permission to use this.",
            ephemeral=True,
        )
        return

    if member == interaction.guild.owner or (
        interaction.user.top_role <= member.top_role
        and not interaction.user.guild_permissions.administrator
    ):
        await interaction.response.send_message(
            "You cannot ban that member.",
            ephemeral=True,
        )
        return

    reason = reason or "No reason provided"

    await safely_dm(
        member,
        f"You were banned from {interaction.guild.name}.\nReason: {reason}",
    )

    try:
        await member.ban(
            reason=reason,
            delete_message_seconds=0,
        )

        await interaction.response.send_message(
            f"{member} was banned. Reason: {reason}",
        )

        await send_log(
            interaction.guild,
            "Member Banned",
            (
                f"{member} was banned by "
                f"{interaction.user.mention}.\nReason: {reason}"
            ),
            discord.Color.red(),
        )

    except discord.Forbidden:
        await interaction.response.send_message(
            "I cannot ban that member. Check my role position and permissions.",
            ephemeral=True,
        )

@bot.tree.command(
    name="purge",
    description="Delete recent messages from this channel.",
)
@app_commands.describe(
    amount="Number of messages to delete, from 1 to 100.",
)
async def purge_messages(
    interaction: discord.Interaction,
    amount: app_commands.Range[int, 1, 100],
) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not interaction.user.guild_permissions.manage_messages
    ):
        await interaction.response.send_message(
            "You need Manage Messages permission to use this.",
            ephemeral=True,
        )
        return

    if not isinstance(interaction.channel, discord.TextChannel):
        await interaction.response.send_message(
            "This command can only be used in a text channel.",
            ephemeral=True,
        )
        return

    await interaction.response.defer(ephemeral=True)

    try:
        deleted = await interaction.channel.purge(limit=amount)

        await interaction.followup.send(
            f"Deleted {len(deleted)} message(s).",
            ephemeral=True,
        )

        await send_log(
            interaction.guild,
            "Messages Purged",
            (
                f"{interaction.user.mention} deleted "
                f"{len(deleted)} message(s) in "
                f"{interaction.channel.mention}."
            ),
        )

    except discord.Forbidden:
        await interaction.followup.send(
            "I cannot delete messages in this channel.",
            ephemeral=True,
        )

@bot.tree.command(
    name="lock",
    description="Prevent regular members from sending messages here.",
)
async def lock_channel(interaction: discord.Interaction) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not interaction.user.guild_permissions.manage_channels
    ):
        await interaction.response.send_message(
            "You need Manage Channels permission to use this.",
            ephemeral=True,
        )
        return

    if not isinstance(interaction.channel, discord.TextChannel):
        await interaction.response.send_message(
            "This command can only be used in a text channel.",
            ephemeral=True,
        )
        return

    await interaction.channel.set_permissions(
        interaction.guild.default_role,
        send_messages=False,
        reason=f"Locked by {interaction.user}",
    )

    await interaction.response.send_message(
        embed=make_embed(
            "Channel Locked",
            (
                f"{interaction.channel.mention} has been locked by "
                f"{interaction.user.mention}."
            ),
        ),
    )

@bot.tree.command(
    name="unlock",
    description="Allow regular members to send messages here again.",
)
async def unlock_channel(interaction: discord.Interaction) -> None:
    if (
        not isinstance(interaction.user, discord.Member)
        or not interaction.user.guild_permissions.manage_channels
    ):
        await interaction.response.send_message(
            "You need Manage Channels permission to use this.",
            ephemeral=True,
        )
        return

    if not isinstance(interaction.channel, discord.TextChannel):
        await interaction.response.send_message(
            "This command can only be used in a text channel.",
            ephemeral=True,
        )
        return

    await interaction.channel.set_permissions(
        interaction.guild.default_role,
        send_messages=None,
        reason=f"Unlocked by {interaction.user}",
    )

    await interaction.response.send_message(
        embed=make_embed(
            "Channel Unlocked",
            (
                f"{interaction.channel.mention} has been unlocked by "
                f"{interaction.user.mention}."
            ),
        ),
    )

auto_reply_times: dict[tuple[int, str], float] = {}

async def send_auto_reply(
    message: discord.Message,
    reply_type: str,
    embed: discord.Embed,
) -> None:
    key = (message.channel.id, reply_type)
    now = time.monotonic()

    if now - auto_reply_times.get(key, 0) < AUTO_REPLY_COOLDOWN:
        return

    auto_reply_times[key] = now

    try:
        await message.channel.send(embed=embed)
    except discord.HTTPException:
        pass

@bot.event
async def on_message(message: discord.Message) -> None:
    if message.author.bot:
        return

    await bot.process_commands(message)

    content = message.content.lower().strip()

    if content in {
        "ip",
        "server ip",
        "what is the ip",
        "what's the ip",
    }:
        await send_auto_reply(
            message,
            "ip",
            get_server_info_embed(),
        )

    elif content in {
        "how do i join",
        "how to join",
        "join the server",
        "join",
    }:
        await send_auto_reply(
            message,
            "join",
            get_join_embed(),
        )

    elif content in {
        "store",
        "shop",
        "store link",
        "webstore",
    }:
        embed = make_embed(
            "Clover Vanilla Store",
            f"Visit the official store here: [Open the store]({STORE_URL})",
        )

        await send_auto_reply(
            message,
            "store",
            embed,
        )

    elif content in {
        "rules",
        "server rules",
    }:
        embed = make_embed(
            "Clover Vanilla Rules",
            f"Please read the complete rules here: [Open the rules]({RULES_URL})",
        )

        await send_auto_reply(
            message,
            "rules",
            embed,
        )

@bot.event
async def on_member_join(member: discord.Member) -> None:
    channel = None

    if WELCOME_CHANNEL_ID is not None:
        configured_channel = member.guild.get_channel(
            WELCOME_CHANNEL_ID,
        )

        if isinstance(configured_channel, discord.TextChannel):
            channel = configured_channel

    if channel is None and isinstance(
        member.guild.system_channel,
        discord.TextChannel,
    ):
        channel = member.guild.system_channel

    if channel is None:
        return

    embed = make_embed(
        f"Welcome to {member.guild.name}!",
        f"{member.mention}\n\n{WELCOME_MESSAGE}",
    )

    embed.set_thumbnail(url=member.display_avatar.url)

    embed.add_field(
        name="Getting Started",
        value=(
            "Use `/info` for the Minecraft server details and "
            "`/help` to see bot commands."
        ),
        inline=False,
    )

    try:
        await channel.send(embed=embed)
    except discord.HTTPException:
        logger.exception("Unable to send welcome message")

@bot.event
async def on_member_remove(member: discord.Member) -> None:
    if WELCOME_CHANNEL_ID is None:
        return

    channel = member.guild.get_channel(WELCOME_CHANNEL_ID)

    if not isinstance(channel, discord.TextChannel):
        return

    embed = make_embed(
        "Member Left",
        f"**{member}** has left the server.",
        discord.Color.orange(),
    )

    try:
        await channel.send(embed=embed)
    except discord.HTTPException:
        pass

@bot.event
async def on_ready() -> None:
    logger.info("Logged in as %s", bot.user)
    logger.info("Connected to %s server(s)", len(bot.guilds))

@bot.event
async def on_app_command_error(
    interaction: discord.Interaction,
    error: app_commands.AppCommandError,
) -> None:
    logger.error("Application command error: %s", error)

    message = "Something went wrong while running that command."

    if isinstance(error, app_commands.CommandOnCooldown):
        message = "That command is temporarily rate limited."

    try:
        if interaction.response.is_done():
            await interaction.followup.send(
                message,
                ephemeral=True,
            )
        else:
            await interaction.response.send_message(
                message,
                ephemeral=True,
            )
    except discord.HTTPException:
        pass

async def setup_hook() -> None:
    bot.add_view(TicketPanelView())
    bot.add_view(TicketCloseView())
    bot.add_view(ApplicationPanelView())
    bot.add_view(ApplicationReviewView())

    if SYNC_GUILD_ID is not None:
        guild = discord.Object(id=SYNC_GUILD_ID)

        bot.tree.copy_global_to(guild=guild)
        await bot.tree.sync(guild=guild)

        logger.info(
            "Slash commands synced to guild %s",
            SYNC_GUILD_ID,
        )
    else:
        await bot.tree.sync()
        logger.info("Global slash commands synced")

bot.setup_hook = setup_hook

def main() -> None:
    initialize_database()

    token = os.getenv("DISCORD_TOKEN")

    if not token:
        raise RuntimeError(
            "DISCORD_TOKEN is not configured in the environment."
        )

    bot.run(token)

if __name__ == "__main__":
    main()

requirements.txt

Txt
discord.py>=2.4.0,<3.0.0
python-dotenv>=1.0.1,<2.0.0

.env

Create a file named .env in the same folder:

Env
DISCORD_TOKEN=PASTE_YOUR_BOT_TOKEN_HERE

SYNC_GUILD_ID=

SERVER_NAME=Clover Vanilla
SERVER_DESCRIPTION=A friendly Minecraft survival community.
SERVER_IP=play.yourserver.net
SERVER_VERSION=Java Edition 1.21+
STORE_URL=https://your-store.example
RULES_URL=https://your-rules.example
DISCORD_INVITE=

WELCOME_MESSAGE=Welcome to Clover Vanilla! Please read the rules and enjoy your stay.

SUPPORT_ROLE_ID=
STAFF_ROLE_ID=
TICKET_CATEGORY_ID=
APPLICATION_CATEGORY_ID=
WELCOME_CHANNEL_ID=
LOG_CHANNEL_ID=

DATABASE_PATH=clover_vanilla.db
AUTO_REPLY_COOLDOWN=30

Install and start it with:

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

Do not share your .env file because it contains your bot token.

devsammc1.1
πŸ“Ž 1 file 3,302 chars
πŸ“„
pasted-code-1785428967881.txt
txt 24 lines
β–Ά
Python 3.13.14
:/home/container$ if [[ -d .git ]] && [[ "${AUTO_UPDATE}" == "1" ]]; then git pull; fi; if [[ ! -z "${PY_PACKAGES}" ]]; then pip install -U --prefix .local ${PY_PACKAGES}; fi; if [[ -f /home/container/${REQUIREMENTS_FILE} ]]; then pip install -U --prefix .local -r ${REQUIREMENTS_FILE}; fi; /usr/local/bin/python /home/container/${PY_FILE}
Python 3.13.14
:/home/container$ if [[ -d .git ]] && [[ "${AUTO_UPDATE}" == "1" ]]; then git pull; fi; if [[ ! -z "${PY_PACKAGES}" ]]; then pip install -U --prefix .local ${PY_PACKAGES}; fi; if [[ -f /home/container/${REQUIREMENTS_FILE} ]]; then pip install -U --prefix .local -r ${REQUIREMENTS_FILE}; fi; /usr/local/bin/python /home/container/${PY_FILE}
Requirement already satisfied: discord.py<3.0.0,>=2.4.0 in ./.local/lib/python3.13/site-packages (from -r requirements.txt (line 1)) (2.7.1)
Requirement already satisfied: python-dotenv<2.0.0,>=1.0.1 in ./.local/lib/python3.13/site-packages (from -r requirements.txt (line 2)) (1.2.2)
Requirement already satisfied: aiohttp<4,>=3.7.4 in ./.local/lib/python3.13/site-packages (from discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (3.14.3)
Requirement already satisfied: audioop-lts in ./.local/lib/python3.13/site-packages (from discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (0.2.2)
Requirement already satisfied: aiohappyeyeballs>=2.5.0 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (2.7.1)
Requirement already satisfied: aiosignal>=1.4.0 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (1.4.0)
Requirement already satisfied: attrs>=17.3.0 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (26.1.0)
Requirement already satisfied: frozenlist>=1.1.1 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (1.8.0)
Requirement already satisfied: multidict<7.0,>=4.5 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (6.7.1)
Requirement already satisfied: propcache>=0.2.0 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (0.5.2)
Requirement already satisfied: yarl<2.0,>=1.17.0 in ./.local/lib/python3.13/site-packages (from aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (1.24.5)
Requirement already satisfied: idna>=2.0 in ./.local/lib/python3.13/site-packages (from yarl<2.0,>=1.17.0->aiohttp<4,>=3.7.4->discord.py<3.0.0,>=2.4.0->-r requirements.txt (line 1)) (3.18)
[notice] A new release of pip is available: 26.1.2 -> 26.2
[notice] To update, run: pip install --upgrade pip
/usr/local/bin/python: can't open file '/home/container/app.py': [Errno 2] No such file or directory
container@pterodactyl~ Server marked as offline...
[Pterodactyl Daemon]: ---------- Detected server process in a crashed state! ----------
[Pterodactyl Daemon]: Exit code: 2
[Pterodactyl Daemon]: Out of memory: false
[Pterodactyl Daemon]: Aborting automatic restart, last crash occurred less than 60 seconds ago.
Kodari AI
KodariJul 30 at 4:29 pm 1

The bot is crashing because Pterodactyl is configured to run:

Plain Text
/home/container/app.py

but that file does not exist:

Plain Text
can't open file '/home/container/app.py': [Errno 2] No such file or directory

Fix one of these:

  1. Upload or rename your bot file to app.py

    • Place it directly in /home/container/.

  2. Change the startup variable

    • In your Pterodactyl server startup settings, set:

    Plain Text
    PY_FILE=your_actual_filename.py
    

    For example:

    Plain Text
    PY_FILE=bot.py
    
  3. Make sure the file is not inside a subfolder. If it is, use the relative path:

    Plain Text
    PY_FILE=src/bot.py
    

Your dependencies installed successfully. This is a file-path/startup configuration issue, not a Discord.py or memory problem.

devsammc1.1

wait so what do i put

Kodari AI
KodariJul 30 at 4:30 pm 1

In your Pterodactyl panel, go to Startup and set:

Plain Text
PY_FILE=bot.py

β€”but only if your bot file is actually named bot.py.

If your Python file is named main.py, use:

Plain Text
PY_FILE=main.py

If you want to use the current setting:

Plain Text
PY_FILE=app.py

then rename your bot file to app.py and upload it directly to /home/container/.

Your files should look like:

Plain Text
/home/container/
β”œβ”€β”€ bot.py
β”œβ”€β”€ requirements.txt
└── .env

The simplest option is to rename your bot file to app.py, then keep:

Plain Text
PY_FILE=app.py
devsammc1.1

im so confused?

Kodari AI
KodariJul 30 at 4:30 pm 1

No problem β€” here’s the simple version:

1. Open your Pterodactyl server

Go to Files.

2. Find your Python bot file

Look for a file ending in .py, such as:

Plain Text
bot.py
main.py

3. Go to Startup

Find the variable named:

Plain Text
PY_FILE

Set it to the exact filename you found.

For example, if your file is named main.py, enter:

Plain Text
main.py

Do not enter /home/container/ or the long command.

4. Start the server again

If there is no .py file in Files, upload your bot code as a file named:

Plain Text
app.py

Then set:

Plain Text
PY_FILE=app.py

The file you pasted is only the error log, not the bot file.

devsammc1.1

what now?

1 image attached
Kodari AI
KodariJul 30 at 4:31 pm 1

You already have the correct bot file: bot.py.

Do this:

  1. Open your server’s Startup tab.

  2. Find the variable named PY_FILE.

  3. Change its value to exactly:

Plain Text
bot.py
  1. Click Save if there is a save button.

  2. Go back to Console and click Start or Restart.

Do not change .env or requirements.txt. Your file layout is correct.

devsammc1.1

if [[ -d .git ]] && [[ "0" == "1" ]]; then git pull; fi; if [[ ! -z "" ]]; then pip install -U --prefix .local ; fi; if [[ -f /home/container/${REQUIREMENTS_FILE} ]]; then pip install -U --prefix .local -r ${REQUIREMENTS_FILE}; fi; /usr/local/bin/python /home/container/app.py

Kodari AI
KodariJul 30 at 4:32 pm 1

That command is still trying to run app.py, but your file is bot.py.

In the Startup tab, change:

Plain Text
PY_FILE=app.py

to:

Plain Text
PY_FILE=bot.py

Then save and restart the server.

The startup command should end with:

Plain Text
/usr/local/bin/python /home/container/bot.py

If there is no PY_FILE field, edit the command itself and replace only:

Plain Text
/home/container/app.py

with:

Plain Text
/home/container/bot.py
devsammc1.1

so what do i put

Kodari AI
KodariJul 30 at 4:32 pm 1

Put this in the PY_FILE field:

Plain Text
bot.py

Do not paste the entire startup command. Then save and restart the server.

devsammc1.1
1 image attached
Kodari AI
KodariJul 30 at 4:33 pm 1

In the box labeled APP PY FILE, replace:

Plain Text
app.py

with:

Plain Text
bot.py

Then scroll down and click Save Changes if shown. After that, go to Console and start/restart the server.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
README.md
requirements.txt
Code
4 1,571
bot.py
import asyncio
import datetime
import logging
import os
import re
import sqlite3
import time
from typing import Optional

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

load_dotenv()

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

DATABASE_PATH = os.getenv("DATABASE_PATH", "clover_vanilla.db")
SERVER_NAME = os.getenv("SERVER_NAME", "Clover Vanilla")
SERVER_DESCRIPTION = os.getenv(
    "SERVER_DESCRIPTION",
    "A friendly Minecraft survival community.",
)
SERVER_IP = os.getenv("SERVER_IP", "play.example.net")
SERVER_VERSION = os.getenv("SERVER_VERSION", "Java Edition")
STORE_URL = os.getenv("STORE_URL", "https://example.com/store")
RULES_URL = os.getenv("RULES_URL", "https://example.com/rules")
DISCORD_INVITE = os.getenv("DISCORD_INVITE", "")
WELCOME_MESSAGE = os.getenv(
    "WELCOME_MESSAGE",
    "Welcome to Clover Vanilla! Please read the rules and enjoy your stay.",
)
AUTO_REPLY_COOLDOWN = int(os.getenv("AUTO_REPLY_COOLDOWN", "30"))


def env_int(name: str) -> Optional[int]:
    value = os.getenv(name, "").strip()
    if not value:
        return None
    try:
        return int(value)
    except ValueError:
        logger.warning("Invalid integer configured for %s", name)
        return None


SUPPORT_ROLE_ID = env_int("SUPPORT_ROLE_ID")
STAFF_ROLE_ID = env_int("STAFF_ROLE_ID") or SUPPORT_ROLE_ID
TICKET_CATEGORY_ID = env_int("TICKET_CATEGORY_ID")
APPLICATION_CATEGORY_ID = env_int("APPLICATION_CATEGORY_ID")
WELCOME_CHANNEL_ID = env_int("WELCOME_CHANNEL_ID")
LOG_CHANNEL_ID = env_int("LOG_CHANNEL_ID")
SYNC_GUILD_ID = env_int("SYNC_GUILD_ID")

GREEN = discord.Color.from_rgb(46, 204, 113)
DARK_GREEN = discord.Color.from_rgb(25, 135, 84)

intents = discord.Intents.default()
intents.members = True
intents.message_content = True

bot = commands.Bot(
    command_prefix="!",
    intents=intents,
    help_command=None,
    allowed_mentions=discord.AllowedMentions(
        everyone=False,
        roles=True,
        users=True,
    ),
)


def initialize_database() -> None:
    with sqlite3.connect(DATABASE_PATH) as connection:
        connection.executescript(
            """
            CREATE TABLE IF NOT EXISTS warnings (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                guild_id INTEGER NOT NULL,
                user_id INTEGER NOT NULL,
                moderator_id INTEGER NOT NULL,
                reason TEXT NOT NULL,
                created_at TEXT NOT NULL
            );

            CREATE TABLE IF NOT EXISTS tickets (
                channel_id INTEGER PRIMARY KEY,
                guild_id INTEGER NOT NULL,
                opener_id INTEGER NOT NULL,
                created_at TEXT NOT NULL
            );

            CREATE TABLE IF NOT EXISTS applications (
                channel_id INTEGER PRIMARY KEY,
                guild_id INTEGER NOT NULL,
                applicant_id INTEGER NOT NULL,
                status TEXT NOT NULL DEFAULT 'pending',
                created_at TEXT NOT NULL
            );
            """
        )


def database_execute(query: str, parameters: tuple = ()) -> None:
    with sqlite3.connect(DATABASE_PATH) as connection:
        connection.execute(query, parameters)
        connection.commit()


def database_fetchone(
    query: str,
    parameters: tuple = (),
) -> Optional[tuple]:
    with sqlite3.connect(DATABASE_PATH) as connection:
        return connection.execute(query, parameters).fetchone()


def database_fetchall(query: str, parameters: tuple = ()) -> list[tuple]:
    with sqlite3.connect(DATABASE_PATH) as connection:
        return connection.execute(query, parameters).fetchall()


def make_embed(
    title: str,
    description: str = "",
    color: discord.Color = GREEN,
) -> discord.Embed:
    embed = discord.Embed(
        title=title,
        description=description,
        color=color,
        timestamp=discord.utils.utcnow(),
    )
    embed.set_footer(text="Clover Vanilla")
    return embed


def get_configured_role(
    guild: discord.Guild,
    role_id: Optional[int],
) -> Optional[discord.Role]:
    if role_id is None:
        return None
    return guild.get_role(role_id)


def get_configured_category(
    guild: discord.Guild,
    category_id: Optional[int],
) -> Optional[discord.CategoryChannel]:
    if category_id is None:
        return None
    category = guild.get_channel(category_id)
    if isinstance(category, discord.CategoryChannel):
        return category
    return None


def is_staff(member: discord.Member) -> bool:
    if member.guild_permissions.administrator:
        return True
    if member.guild_permissions.manage_guild:
        return True
    staff_role = get_configured_role(member.guild, STAFF_ROLE_ID)
    return staff_role is not None and staff_role in member.roles


def has_moderation_permission(member: discord.Member) -> bool:
    return member.guild_permissions.administrator or member.guild_permissions.moderate_members


async def deny_if_not_staff(interaction: discord.Interaction) -> bool:
    if not isinstance(interaction.user, discord.Member) or not is_staff(interaction.user):
        await interaction.response.send_message(
            "You need the configured staff role or Manage Server permission to use this.",
            ephemeral=True,
        )
        return True
    return False


async def send_log(
    guild: discord.Guild,
    title: str,
    description: str,
    color: discord.Color = GREEN,
) -> None:
    if LOG_CHANNEL_ID is None:
        return
    channel = guild.get_channel(LOG_CHANNEL_ID)
    if isinstance(channel, discord.TextChannel):
        try:
            await channel.send(embed=make_embed(title, description, color))
        except discord.HTTPException: