Skip to main content

Initialize a production-ready Discord.py bot in just 4 lines of code. Smart and automated command syncing, easy-to-use in-Discord dashboard, logging backend, and more. Made by likerofturtles

Project description

Dopamine Framework

Dopamine Framework is a framework for discord.py which allows you to initialize a production-ready Discord bot in just 4 lines of code. In technical terms, this is a Flexible Boilerplate Framework (not to be confused with opinionated boilerplate framework). It is designed to streamline the development of scalable Discord applications by automating the process of registering commands, diagnosing the bot, and various other utilities such as a paginator helper and "Private View" helpers which let only the user who initiated the interaction to interact with the components like buttons.

Made by likerofturtles.


Installing

Use Python 3.12 or higher:

# Linux/MacOS
python3 -m pip install -U dopamine-framework
# Windows
py -3 -m pip install -U dopamine-framework

Features

1. Smart Command Syncs

The framework includes a Command Registry that compares local command states with remote Discord API states. This ensures that global and guild-specific slash commands are only synced when changes are detected, preventing unnecessary API overhead and rate-limit triggers.

2. Diagnostics

The built-in Diagnostics "cog" (module) provides real-time monitoring of the bot's health, including:

  • Latency: High precision API, Heartbeat, and Round-trip latency monitoring.
  • Resource Utilization: CPU and RAM usage tracking via psutil.
  • Graphs: Generate graphs for the bot's latency for visual performance auditing.
  • Host Device Metrics: Integration with system sensors to report host location and battery status, if available.

3. In-Discord Owner Dashboard

No need for terminal access/SSH. This simple to use and feature-rich dashboard for bot owners allows you to unload/reload cogs on the fly, restart the bot, or check logs, accessed using /od. This allows bot owner(s) to manage, diagnose the bot right within Discord itself. This dashboard allows the bot to run idefinitely without restarts:

  • Cog Management: Dynamic loading, unloading, and reloading of cogs.
  • Power State: Remote shutdown and process-level restarts.
  • Logs: Real-time retrieval of log files via the Discord UI.
  • Manual Command Syncs: Sync commands manually globally or within only the current guild.

4. Built-in Logging Backend

  • A robust Logging Manager utilizing aiosqlite that can be plugged into any feature of your bot to implement a logging system, such as for mod logs, action logs, etc.

Comparison (with Sapphire Framework and bare-bones discord.py)

Feature Dopamine Framework Sapphire (js/ts) discord.py
Easy Setup ✅ (minimal boilerplate) (Lots of boilerplate)
Python's ease of use
Smart Commands Sync ✅ (Built-in) (Through plugins) (not included/standard)
In-Discord Dashboard ✅ (Built-in)
Latency Graphs ✅ (Built-in)
Scalability*
Fast Iteration
Strict TypeScript Rules
Built-in Resource Monitoring
Is it JS, tho?
Wins Imaginary Benchmarks
Gives you that Dopamine rush? ✅ (Built-in)

*Scalability refers to ability to run without problems when the bot is in tens of thousands of servers or more. While it's a common myth that "Python is bloated", that's not true in the context of Discord bots. The real bottleneck in popular Discord bots always comes down to network, not code execution time or memory usage.


Implementation Example

To initialize a bot using the Dopamine Framework, follow the following example:

import discord
from dopamineframework import Bot

bot = Bot(command_prefix="?", cogs_path="your cogs/modules folder path here*", logging_path="path to .sqlite, .db, or .db3 file; only define if you want to use this logging backend.", default_diagnostics=True, intents=discord.Intents.default()) # If no cogs folder is defined, it will default to "cogs". If no logging path, logging will be disabled.

bot.run("YOUR_BOT_TOKEN_HERE")

*Note: All .py files will be attempted to be loaded in the folder. It's recommended to only use the defined path for cogs/extensions/modules.


Requirements

  • discord.py
  • aiosqlite
  • psutil
  • Pillow
  • geocoder

Discord Logging Manager Documentation

The LoggingManager is an asynchronous backend designed to facilitate per-guild Discord channel logging for things such as mod logs, action logs, and more. Not to be confused with the logs in a discord.log or similar file in discord.py bots that sits on the host machine and logs info about the bot.

  • self.logger.get(guild.id): Get the logging channel, where guild.id the guild whose logging channel's ID you want to get.
  • self.logger.set(guild.id, channel_id): Set the logging channel, where guild.id the guild and channel_id is the ID of the channel to be set for logging.
  • self.logger.delete(guild.id): Delete the logging channel, where guild.id the guild whose logging channel you want to delete.

Example:

import discord
from dopamineframework import Bot

bot = Bot(command_prefix="?", cogs_path="modules", logging_path="logging.db", default_diagnostics=True, intents=discord.Intents.default()) # Define logging path to enable logging. If no logging path, logging will be disabled.

bot.run("YOUR_BOT_TOKEN_HERE")

License & Attribution

Dopamine Framework is licensed under the Apache License 2.0.

How to Credit

While you are free to use this framework for private or commercial bots, I require explicit credit. Please include a link to this repository or a mention of "Dopamine Framework" in:

  1. Your project's README or documentation.
  2. Your bot's info/credits command (for example /about or /help).

Example: "Built with Dopamine Framework"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dopamine_framework-1.3.1.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dopamine_framework-1.3.1-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file dopamine_framework-1.3.1.tar.gz.

File metadata

  • Download URL: dopamine_framework-1.3.1.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dopamine_framework-1.3.1.tar.gz
Algorithm Hash digest
SHA256 df4b1fdebcc76d025022df700ccd34c91563895b1eebe118e950430a4cd2c778
MD5 0a8baf743a0fa7be59914ef6ca2f6bcc
BLAKE2b-256 8032288ebac0afabbc92b6c938de62d5bc6d1b4d43c4900c7c73ec56ac50e7e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dopamine_framework-1.3.1.tar.gz:

Publisher: publish.yml on likerofturtles/dopamine-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dopamine_framework-1.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dopamine_framework-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3886c6cfa3d6d39726e661b44bad500582befbd313b507a54a0e324a052fa68
MD5 46c3be010f0d0d7cac93bd0240ba716a
BLAKE2b-256 ebe17dd267d7b8a7c50f299a13567fc55b7c580515c9e31a6f39f81037d2589d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dopamine_framework-1.3.1-py3-none-any.whl:

Publisher: publish.yml on likerofturtles/dopamine-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page