A minimalist Discord bot framework that communicates directly with Discord Gateway and REST.
Project description
mycord
A minimalist Discord bot wrapper around discord.py.
mycord is designed for beginners:
- One import:
import mycord - Simple bot startup with
bot.start() - Automatic
.envloading forTOKEN - Built-in
bot.dbhelper for SQLite - Lightweight wrapper over
discord.pycommands and events
Installation
pip install mycord
From source
git clone https://github.com/amri4/mycord.git
cd mycord
pip install -e .
Quick Start
Create a .env file in the same folder as main.py:
TOKEN=your_discord_bot_token_here
Create main.py:
import mycord
bot = mycord.Bot(prefix="!")
@bot.event
async def on_ready():
print("✅ Bot online")
@bot.command(name="ping")
async def ping(ctx):
await ctx.send("Pong!")
bot.start()
Run:
python main.py
mycord.Bot
bot = mycord.Bot(prefix="!", db_name="mycord_data.db")
The main bot class. It is a lightweight wrapper around discord.py that exposes commands, events, and database helpers.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
prefix |
str |
"!" |
Command prefix |
token |
str |
None |
Discord bot token; if omitted, TOKEN is loaded from .env or environment |
db_name |
str |
"mycord_data.db" |
SQLite filename |
Methods
bot.start(token=None)
Start the bot. If token is omitted, mycord loads TOKEN automatically.
bot.start()
bot.run_bot(token_env_name="TOKEN")
Alias for bot.start() that reads the token from an environment variable name.
bot.run_bot()
bot.get_env(key, default=None)
Read any environment variable.
token = bot.get_env("TOKEN")
Events and Commands
Events
Use @bot.event to register event handlers.
@bot.event
async def on_ready():
print("Bot online")
@bot.event
async def on_message(ctx):
print(ctx.content)
Commands
Use @bot.command(name="...") to register commands.
@bot.command(name="hello")
async def hello(ctx):
await ctx.send("Hello!")
Database Helpers
mycord includes a lightweight SQLite wrapper available as bot.db.
bot.create_table("users", "id INTEGER PRIMARY KEY, name TEXT")
Common methods available on bot and bot.db:
create_table(name, columns)insert(table, columns, values)insert_replace(table, columns, values)fetchone(table, condition=None, values=())fetchall(table)update(table, set_values, condition, values)delete(table, condition, values)exists(table, condition, values)
Utilities
mycord.Tools
if mycord.Tools.chance(25):
print("1 in 4 chance")
print(mycord.Tools.timestamp())
mycord.os
A shortcut to Python's standard os module.
prefix = mycord.os.getenv("PREFIX", "!")
Example: Bot with Database
import mycord
bot = mycord.Bot()
@bot.event
async def on_ready():
bot.create_table("points", "user_id INTEGER PRIMARY KEY, amount INTEGER DEFAULT 0")
@bot.command(name="points")
async def points(ctx):
row = bot.fetchone("points", "user_id = ?", (ctx.author.id,))
total = row[1] if row else 0
await ctx.send(f"Points: {total}")
bot.start()
Requirements
- Python
>=3.8 discord.py>=2.0.0python-dotenv>=1.0.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mycord-1.0.7.tar.gz.
File metadata
- Download URL: mycord-1.0.7.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff6a31c909fd73e0b06ce9b6d65df51c8c3b474c67d99ffa16d4ac465b850fee
|
|
| MD5 |
1e86ebc86ae10eaffe30ef2bc5e2aa4d
|
|
| BLAKE2b-256 |
a2e38570def469df10c55027d6aae0b6ffc860f3637cee6f9b4be9d507ebaa93
|
Provenance
The following attestation bundles were made for mycord-1.0.7.tar.gz:
Publisher:
publish.yml on amri4/mycord
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mycord-1.0.7.tar.gz -
Subject digest:
ff6a31c909fd73e0b06ce9b6d65df51c8c3b474c67d99ffa16d4ac465b850fee - Sigstore transparency entry: 1807501951
- Sigstore integration time:
-
Permalink:
amri4/mycord@6306259eb9ed8d219a1340aefff8c5f9cafcc002 -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/amri4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6306259eb9ed8d219a1340aefff8c5f9cafcc002 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mycord-1.0.7-py3-none-any.whl.
File metadata
- Download URL: mycord-1.0.7-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d701ed77ddc7da7f7dc2ed0043343b7b3e1abc0dfc022b04ce24de2ce4a34fa
|
|
| MD5 |
e135df9668d8c772af48b47fa605a0fd
|
|
| BLAKE2b-256 |
ad8819ddc41d6997c1d2ee73c15f0547bd8519be151eb8c4b44fe75519a4a53a
|
Provenance
The following attestation bundles were made for mycord-1.0.7-py3-none-any.whl:
Publisher:
publish.yml on amri4/mycord
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mycord-1.0.7-py3-none-any.whl -
Subject digest:
7d701ed77ddc7da7f7dc2ed0043343b7b3e1abc0dfc022b04ce24de2ce4a34fa - Sigstore transparency entry: 1807501974
- Sigstore integration time:
-
Permalink:
amri4/mycord@6306259eb9ed8d219a1340aefff8c5f9cafcc002 -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/amri4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6306259eb9ed8d219a1340aefff8c5f9cafcc002 -
Trigger Event:
release
-
Statement type: