dsnah381
📎 1 file 7,245 chars
📄
pasted-code-1787487726159.txt
txt 371 lines
▶
Build a production-ready Discord bot specifically for a developer/project promotion platform.

TECH STACK:

* Python 3.12+
* discord.py 2.x
* SQLite for development, structured so PostgreSQL can easily be added later
* Environment variables for the Discord bot token and configuration
* Modular architecture with separate files/cogs for each feature
* Async database operations
* Slash commands only where appropriate
* Discord buttons, select menus, and modals for user interaction

CORE PURPOSE:
This bot acts as the management system for a project-promotion Discord server. Developers submit their projects, staff review them, and approved projects are automatically formatted and published into designated channels.

MAIN WORKFLOW:

1. /submit
   Allow developers to submit a project through a Discord modal.

Collect:

* Project name
* Description
* Project type/category
* Platform
* Developer/creator
* Project URL
* Discord invite URL
* Thumbnail/image URL
* Tags
* Optional price
* Optional version
* Optional additional information

After submission:

* Generate a unique project ID
* Store the project in the database
* Set status to PENDING
* Send a polished submission embed to the configured staff review channel
* Add Approve and Reject buttons
* Notify the developer that their submission is awaiting review

2. /review
   Create a staff-only command for viewing pending submissions.

Display:

* Project information
* Submitter
* Submission date
* Project ID
* Current status

Include buttons for:

* Approve
* Reject
* Request Changes
* View Details

3. /approve
   Staff-only command.

When a project is approved:

* Change status to APPROVED
* Automatically create a polished project embed
* Publish it to the configured project listing channel
* Add buttons such as:

  * Visit Project
  * Join Discord
  * View Creator
* Record the publication timestamp
* Notify the developer
* Log the approval in a staff log channel

4. /reject
   Staff-only command.

Require a rejection reason.

Then:

* Change status to REJECTED
* Save the reason
* Notify the developer
* Log the action

5. /feature
   Staff-only command.

Allow staff to feature an approved project.

The project should be posted or reposted into:
#✨-featured-projects

Add a Featured badge/status to the embed.

6. /stats
   Allow developers to view statistics for their projects.

Show:

* Total impressions
* Total button clicks
* Project views
* Discord invite clicks
* Website/project link clicks
* Feature status
* Submission date
* Approval date
* Ranking compared to other projects if possible

Use a clean Discord embed with statistics.

7. /creator
   Create developer profiles.

A creator profile should include:

* Discord username
* Creator ID
* Bio
* Projects
* Total impressions
* Total clicks
* Featured projects
* Join date
* Verification status

Allow developers to update their profile.

8. PROJECT SEARCH

Create:
/projects
/project 
/search 

Users should be able to browse approved projects.

Support filters such as:

* Category
* Platform
* Creator
* Featured
* Newest
* Most popular

9. ANALYTICS

Track project interactions using Discord buttons.

Track:

* Project embed views when realistically measurable
* Website button clicks
* Discord invite clicks
* Creator profile clicks
* Featured project interactions

Do not claim to track impressions that Discord's API cannot actually measure.

Store analytics in the database.

10. ADMIN CONFIGURATION

Create an admin-only configuration system.

Commands should include:
/config review-channel
/config projects-channel
/config featured-channel
/config logs-channel
/config role
/config category
/config setup

Store server-specific configuration in the database.

11. PERMISSIONS

Implement Discord permission checks.

Roles:

* Owner
* Administrator
* Moderator
* Reviewer
* Verified Developer

Only authorized staff can:

* Review submissions
* Approve projects
* Reject projects
* Feature projects
* Configure the bot

Normal members can:

* Submit projects
* Browse projects
* View statistics for their own projects
* Manage their creator profile

12. DATABASE DESIGN

Create proper database tables for:

users
creators
projects
submissions
project_stats
project_clicks
reviews
featured_projects
guild_config
audit_logs

Use foreign keys and indexes where appropriate.

Each project should have:

* Internal database ID
* Public project ID
* Creator ID
* Status
* Creation timestamp
* Approval timestamp
* Feature status

13. EMBED DESIGN

Make all bot embeds polished and consistent.

Use:

* Project title
* Description
* Creator
* Category
* Platform
* Version
* Price
* Tags
* Thumbnail
* Project ID
* Status
* Buttons

Avoid excessive emojis.

14. AUDIT LOGGING

Log important staff actions:

* Submission
* Approval
* Rejection
* Request changes
* Feature
* Unfeature
* Project deletion
* Configuration changes

Include:

* Staff member
* Project ID
* Action
* Reason when applicable
* Timestamp

15. ERROR HANDLING

Implement:

* Global error handling
* Permission errors
* Invalid project IDs
* Database errors
* Missing configuration
* Expired interactions
* Duplicate submissions
* Invalid URLs

Return clean user-friendly Discord messages.

16. SECURITY

Never hardcode the bot token.

Use:
DISCORD_TOKEN

in an environment file.

Validate submitted URLs.

Prevent users from manipulating project IDs or accessing other developers' private statistics.

Use Discord permission checks AND application-level authorization.

17. MODULAR PROJECT STRUCTURE

Create a clean structure similar to:

bot/
├── main.py
├── config.py
├── database/
│   ├── database.py
│   ├── models.py
│   └── migrations.py
├── cogs/
│   ├── submissions.py
│   ├── moderation.py
│   ├── projects.py
│   ├── creators.py
│   ├── analytics.py
│   ├── configuration.py
│   └── admin.py
├── views/
│   ├── submission_view.py
│   ├── review_view.py
│   └── project_view.py
├── services/
│   ├── project_service.py
│   ├── analytics_service.py
│   └── notification_service.py
├── utils/
│   ├── embeds.py
│   ├── permissions.py
│   ├── validators.py
│   └── logging.py
├── requirements.txt
├── .env.example
└── README.md

IMPORTANT DEVELOPMENT REQUIREMENTS:

Build the bot as an actual functional application, not a mockup.

Do not leave commands as placeholders.

Do not use fake database functions.

Do not hardcode channel IDs.

Do not hardcode role IDs.

Use configuration/database values instead.

Make the system guild-aware so it can support multiple Discord servers later.

Use persistent Discord views so buttons continue working after bot restarts.

Include setup instructions and a complete requirements.txt.

Prioritize reliability, clean architecture, maintainability, and an excellent Discord UX.

Start by creating the complete project structure and core database architecture, then implement each module.
Kodari AI
KodariAug 23 at 12:28 pm 2
ProjectPromoBot
A Discord bot for managing a developer project promotion platform. Developers submit projects via modals, staff review them, and approved projects are published to designated channels. Features include submission workflow with approve/reject/request-changes buttons, project listing and search, creator profiles, analytics tracking button clicks, staff-only moderation commands, admin configuration, audit logging, and persistent Discord views. Built with Python 3.12, discord.py 2.x, SQLite with PostgreSQL-ready schema, modular cogs, async database operations, and environment-based configuration.
  1. Create the async SQLite schema and service layer for guild configuration, projects, reviews, creators, publishing, and analytics.

  2. Add persistent Discord views, polished embeds, validation, permission checks, and audit/notification utilities.

  3. Implement submission, moderation, project browsing/statistics, creator profiles, analytics, configuration, and admin cogs.

  4. Add the bot entry point, environment template, dependency list, and setup documentation.

Created the complete modular Discord project-promotion bot with:

  • Async SQLite database schema and repository layer

  • Guild-specific configuration

  • Project submissions with modal forms

  • Persistent submission review and project interaction views

  • Staff approval, rejection, change requests, featuring, and deletion

  • Project browsing, searching, filtering, and statistics

  • Creator profiles and profile editing

  • Analytics for tracked views and button interactions

  • Audit logging and creator notifications

  • Permission checks for staff and administrators

  • Environment-based configuration

  • Requirements, .env.example, .gitignore, and setup documentation

Run it with:

Shell
pip install -r requirements.txt
cp .env.example .env
python -m bot.main
Kodari can make mistakes. Review important code before using.
Files
bot
.gitignore
DISCORD_TOKEN
requirements.txt
Code
32 1,191
bot/main.py
import logging

import discord
from discord import app_commands
from discord.ext import commands

from bot.config import Settings
from bot.database import Database
from bot.services.analytics_service import AnalyticsService
from bot.services.project_service import ProjectService
from bot.utils.logging import configure_logging
from bot.utils.permissions import is_staff
from bot.views.project_view import ProjectView
from bot.views.review_view import ReviewView

log = logging.getLogger(__name__)


class PromotionBot(commands.Bot):
    def __init__(self, settings: Settings):
        intents = discord.Intents.default()
        super().__init__(command_prefix=commands.when_mentioned, intents=intents)
        self.settings = settings
        self.db = Database(settings.database_path)
        self.analytics = AnalyticsService(self.db)
        self.project_service = ProjectService(self, self.db)

    async def setup_hook(self) -> None:
        await self.db.connect()
        for extension in ("bot.cogs.submissions", "bot.cogs.moderation", "bot.cogs.projects", "bot.cogs.creators",
                          "bot.cogs.analytics", "bot.cogs.configuration", "bot.cogs.admin"):
            await self.load_extension(extension)
        for guild in await self.fetch_guilds().flatten() if False else []:
            pass
        if self.settings.dev_guild_id:
            guild = discord.Object(id=self.settings.dev_guild_id)
            self.tree.copy_global_to(guild=guild)
            await self.tree.sync(guild=guild)
        else:
            await self.tree.sync()
        for row in await self.db.fetchall("SELECT public_id FROM projects WHERE status='APPROVED' AND published_message_id IS NOT NULL"):
            self.add_view(ProjectView(row["public_id"]))
        for guild in await self.db.fetchall("SELECT DISTINCT guild_id FROM projects"):
            for public_id in await self.db.list_ids_by_status(guild["guild_id"], "PENDING"):
                self.add_view(ReviewView(public_id))

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

    async def is_staff(self, interaction: discord.Interaction) -> bool:
        return await is_staff(interaction)

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

    async def on_tree_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError) -> None:
        if isinstance(error, app_commands.CheckFailure):
            message = str(error) or "You do not have permission to use this command."
        elif isinstance(error, app_commands.CommandOnCooldown):
            message = f"Try again in {error.retry_after:.1f} seconds."
        else:
            log.exception("Unhandled application command error", exc_info=error)
            message = "Something went wrong while processing that command."
        if interaction.response.is_done():
            await interaction.followup.send(message, ephemeral=True)
        else:
            await interaction.response.send_message(message, ephemeral=True)


def run() -> None:
    configure_logging()
    settings = Settings.from_environment()
    bot = PromotionBot(settings)
    bot.tree.on_error = bot.on_tree_error
    bot.run(settings.token, log_handler=None)


if __name__ == "__main__":
    run()