xotiicnoaim.smk

Discord Server Manager Bot /setup sistema welcome verifica nuovi membri ruoli automatici ticket moderazione log giveaway messaggi embed personalizzati pannello admin configurazione tramite /config database compatibilità con hosting tipo Quaxly

Kodari AI
KodariSep 9 at 9:24 pm 2
DiscordServerManager
A comprehensive Discord bot for server administration. It provides slash commands for setup, welcome messages for new members, automatic role assignment, ticket system, moderation tools, activity logs, giveaway management, custom embed messages, and an admin panel. Configuration is handled through /config commands with persistent database storage, ensuring compatibility with hosting platforms like Quaxly.
  1. Create the Discord bot core, SQLite persistence layer, configuration, and deployment files.

  2. Add setup/configuration flows for welcome, verification, automatic roles, logs, tickets, and admin controls.

  3. Add moderation, custom embeds, ticket handling, and giveaway functionality with background expiry processing.

  4. Document local and Quaxly-style deployment using environment variables and persistent storage.

Creato il progetto completo del bot Discord in discord.py, con:

  • /setup e /admin

  • configurazione tramite /config

  • welcome system

  • verifica membri con ruolo

  • ruoli automatici

  • ticket privati

  • moderazione: ban, kick, timeout, warn e clear

  • canale log

  • giveaway automatici

  • embed personalizzati

  • database SQLite persistente

  • .env per il token

  • Dockerfile e istruzioni per hosting tipo Quaxly

  • supporto a TEST_GUILD_ID per sincronizzazione rapida dei comandi slash

xotiicnoaim.smk

Fammi scaricare il bot

Kodari AI
KodariSep 9 at 9:30 pm 1

Puoi scaricare il progetto completo dalla sezione File del progetto dell’interfaccia: include tutti i file del bot, tra cui main.py, cartella bot/, requirements.txt, .env.example, Dockerfile e README.md.

Prima di avviarlo:

  1. Rinomina .env.example in .env.

  2. Inserisci il token del bot:

    Env
    DISCORD_TOKEN=il_tuo_token
    
  3. Installa le dipendenze:

    Shell
    pip install -r requirements.txt
    
  4. Avvia il bot:

    Shell
    python main.py
    

Per Quaxly, carica tutti i file mantenendo la struttura delle cartelle e imposta DISCORD_TOKEN nelle variabili d’ambiente dell’hosting.

Kodari can make mistakes. Review important code before using.
Files
bot
.gitignore
Dockerfile
main.py
README.md
requirements.txt
Code
19 1,408
main.py
import logging
import os

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

from bot.cogs.admin import AdminCog
from bot.cogs.configuration import ConfigurationCog
from bot.cogs.embeds import EmbedsCog
from bot.cogs.events import EventsCog
from bot.cogs.giveaways import GiveawaysCog
from bot.cogs.moderation import ModerationCog
from bot.cogs.setup import SetupCog
from bot.cogs.tickets import TicketsCog
from bot.database import Database
from bot.settings import Settings
from bot.views import GiveawayView, SetupView, TicketCloseView, TicketPanelView, VerifyView

load_dotenv()

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


class ServerManagerBot(commands.Bot):
    def __init__(self, settings: Settings) -> None:
        intents = discord.Intents.default()
        intents.members = True
        intents.message_content = True

        super().__init__(
            command_prefix="!",
            intents=intents,
            help_command=None,
        )
        self.settings = settings
        self.db = Database(settings.db_path)

    async def setup_hook(self) -> None:
        await self.db.connect()

        await self.add_cog(EventsCog(self))
        await self.add_cog(ConfigurationCog(self))
        await self.add_cog(SetupCog(self))
        await self.add_cog(ModerationCog(self))
        await self.add_cog(TicketsCog(self))
        await self.add_cog(GiveawaysCog(self))
        await self.add_cog(EmbedsCog(self))
        await self.add_cog(AdminCog(self))

        self.add_view(SetupView(self.db))
        self.add_view(VerifyView(self.db))
        self.add_view(TicketPanelView(self.db))
        self.add_view(TicketCloseView(self.db))

        if self.settings.test_guild_id:
            guild = discord.Object(id=self.settings.test_guild_id)
            self.tree.copy_global_to(guild=guild)
            synced = await self.tree.sync(guild=guild)
            logger.info("Sincronizzati %s comandi nel server di test %s", len(synced), guild.id)
        else:
            synced = await self.tree.sync()
            logger.info("Sincronizzati %s comandi globali", len(synced))

    async def close(self) -> None:
        await self.db.close()
        await super().close()


async def handle_app_command_error(
    interaction: discord.Interaction,
    error: app_commands.AppCommandError,
) -> None:
    original = getattr(error, "original", error)
    if isinstance(original, app_commands.MissingPermissions):
        message = "Non hai i permessi necessari per usare questo comando."
    elif isinstance(original, app_commands.BotMissingPermissions):
        message = "Mi mancano i permessi necessari per completare questa azione."
    elif isinstance(original, app_commands.CommandOnCooldown):
        message = "Questo comando è temporaneamente in cooldown."
    else:
        logger.error("Errore nel comando slash", exc_info=original)
        message = "Si è verificato un errore. Controlla i log del bot."

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


def main() -> None:
    token = os.getenv("DISCORD_TOKEN")
    if not token:
        raise RuntimeError("Imposta DISCORD_TOKEN nell'ambiente o nel file .env")

    settings = Settings.from_environment()
    bot = ServerManagerBot(settings)
    bot.tree.on_error = handle_app_command_error
    bot.run(token, log_handler=None)


if __name__ == "__main__":
    main()