Python client for DiscordForge REST API
Project description
discordforge
Python package for interacting with the DiscordForge REST API.
discord.py Compatibility
This package does not conflict with discord.py imports:
discord.pyusesimport discord- this package uses
import discordforge
Use AsyncDiscordForgeClient in discord.py bots to avoid blocking the event loop.
Install
pip install discordforge
For development tools:
pip install "discordforge[dev]"
Quick Start
from discordforge import DiscordForgeClient
client = DiscordForgeClient(api_key="YOUR_API_KEY")
# POST /api/bots/stats
client.post_bot_stats(server_count=1500, shard_count=5, user_count=50000)
# GET /api/bots/:id/votes/check?userId=...
vote = client.check_vote(bot_id="YOUR_BOT_ID", user_id="USER_ID")
print(vote.has_voted, vote.voted_at, vote.next_vote_at)
# GET /api/bots/:id (public endpoint, no API key required)
public_client = DiscordForgeClient()
bot = public_client.get_bot(bot_id="YOUR_BOT_ID")
print(bot.id, bot.name, bot.vote_count, bot.server_count)
# POST /api/external/bots/commands
result = client.sync_commands(
commands=[
{
"name": "ban",
"description": "Ban a user from the server",
"usage": "/ban <user> [reason]",
"category": "Moderation",
},
{
"name": "play",
"description": "Play a song in your voice channel",
"type": 1,
"options": [
{"name": "query", "type": 3, "required": True},
],
},
]
)
print(result.success, result.synced)
Easy Command Sync (discord.py)
Use one call to map and sync your slash commands:
import os
from discordforge import DiscordForgeClient
forge = DiscordForgeClient(api_key=os.environ["DISCORDFORGE_API_KEY"])
# command_source can be bot.tree or an iterable of command objects.
result = forge.sync_from_discordpy(
command_source=bot.tree,
category="General",
limit=200, # auto-truncate to API max by default
strict_limit=False,
)
print(result.success, result.synced)
discord.py Async Example
import os
import discord
from discord.ext import tasks
from discordforge import AsyncDiscordForgeClient
bot = discord.Client(intents=discord.Intents.default())
forge = AsyncDiscordForgeClient(api_key=os.environ["DISCORDFORGE_API_KEY"])
@bot.event
async def on_ready():
post_stats.start()
@tasks.loop(minutes=5)
async def post_stats():
# Keep this endpoint at 1 request per 5 minutes.
await forge.post_bot_stats(
server_count=len(bot.guilds),
shard_count=getattr(bot, "shard_count", None),
)
@bot.event
async def setup_hook():
# Easy one-call command sync from discord.py command tree.
await forge.sync_from_discordpy(command_source=bot.tree, category="General")
Environment Variable Example
import os
from discordforge import DiscordForgeClient
client = DiscordForgeClient(api_key=os.environ["DISCORDFORGE_API_KEY"])
Error Handling
from discordforge import DiscordForgeClient, DiscordForgeAPIError, DiscordForgeValidationError
client = DiscordForgeClient(api_key="YOUR_API_KEY")
try:
client.post_bot_stats(server_count=1500)
except DiscordForgeValidationError as exc:
print("Invalid input:", exc)
except DiscordForgeAPIError as exc:
print("DiscordForge request failed:", exc.status_code, exc)
Notes
sync_commandsaccepts both DiscordForge custom command format and raw Discord API slash command format.sync_from_discordpymaps command objects (name,description,options) and syncs in one call.- The client sends both
Authorizationandx-api-keyheaders when authentication is required. sync_commandsenforces DiscordForge limits (1..200commands).- For
discord.py, preferAsyncDiscordForgeClientto keep the bot loop responsive.
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
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 discordforge-0.2.0.tar.gz.
File metadata
- Download URL: discordforge-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70c52f4330d69234697e3614bd46c9cd216012888946534a6bb93d12476e9262
|
|
| MD5 |
c11792b55bc3b9acfcca0e7efbf0c853
|
|
| BLAKE2b-256 |
01ddb10b895362732332093b86cd895a2a9915d33c3ad75a7f71869ccf3ba6a2
|
File details
Details for the file discordforge-0.2.0-py3-none-any.whl.
File metadata
- Download URL: discordforge-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e183a4e4ae9adf4dcdbbffb244065406534238203f39d249103e08f67c876638
|
|
| MD5 |
1c1dd9e8ff395ae2d4aa537b72d3ef1f
|
|
| BLAKE2b-256 |
b3970a19306c9987064ee1c2432882282f7d29da5b23130cf560a738cacd58b9
|