A lightweight wrapper for Discord's HTTP interactions using py-cord and FastAPI. This library enables you to build Discord bots that work exclusively through Discord's HTTP interactions, without requiring a WebSocket gateway connection.
Pycord REST allows you to build Discord bots that respond to interactions via HTTP endpoints as described in [Discord's interaction documentation](https://discord.com/developers/docs/interactions/receiving-and-responding) and [interaction overview](https://discord.com/developers/docs/interactions/overview#preparing-for-interactions).
This project is built on:
- **FastAPI** - For handling the HTTP server
- **py-cord** - Leveraging Discord command builders and interaction handling
- **uvicorn** - ASGI server implementation
## Installation
```bash
pip install pycord-reactive-bot
```
## Quick Start
```python
from pycord_rest import App
import discord
app = App(intents=discord.Intents.default())
@app.slash_command(name="ping", description="Responds with pong!")
async def ping(ctx):
await ctx.respond("Pong!")
if __name__ == "__main__":
app.run(
token="YOUR_BOT_TOKEN",
public_key="YOUR_PUBLIC_KEY", # From Discord Developer Portal
uvicorn_options={
"host": "0.0.0.0",
"port": 8000
}
)
```
## Usage
### Setting up your bot on Discord
1. Create a bot on the [Discord Developer Portal](https://discord.com/developers/applications)
2. Enable the "Interactions Endpoint URL" for your application
3. Set the URL to your public endpoint where your bot will receive interactions
4. Copy your public key from the Developer Portal to verify signatures
### Features
- Slash Commands
- UI Components (buttons, select menus)
- Modal interactions
- Autocomplete for commands
### Similarities to py-cord
Syntax is equivalent to py-cord, as it is what is being used under the hood, making it easy to adapt existing bots: