This Discord bot is SERVERLESS which means it can run for FREE and be ALWAYS online on Deta Space!
You can also treat this repository as a template for making serverless bots with the discohook library.
/ping
- a simple command that tells you the bot's latency./ask <prompt> [model]
- a command that uses OpenAI's API (ChatGPT).Listening to /ask! | OpenAI
via scheduled actions..
├─ src/ # Source code
│ ├─ actions/ # Files used for scheduled actions
│ │ └─ presence.py # Presence updater (bot status)
│ ├─ assets/ # All asset files
│ │ └─ logo.png # Logo used for space app
│ ├─ commands/ # All command files
│ │ ├─ ask.py # Ask command
│ │ └─ ping.py # Ping command
│ ├─ utils/ # Contains any extra utility files
│ │ └─ helpers.py # Useful functions
│ └─ bot.py # Contains the discohook bot
├─ .gitignore # Hides certain files
├─ Discovery.md # Defines app's space discovery page
├─ LICENSE # License
├─ README.md # Defines this README page
├─ Spacefile # Space app configuration
├─ example.env # Example of an .env file
├─ main.py # Entry point
└─ requirements.txt # Library dependencies
.env
file.
DISCORD_APPLICATION_ID
- Your discord app's ID.DISCORD_PUBLIC_KEY
- Your discord app's public key.DISCORD_BOT_TOKEN
- Your bot's token.OPENAI_API_KEY
- An API key from OpenAI's API.SYNC_PASSWORD
- A password you set to sync commands later on.Interactions Endpoint URL
to <micro_url>/interactions
.
https://discord.com/developers/applications/{application_id}/information
https://chatgpt-1-a1234567.deta.app
<micro_url>/api/dash
to register the slash commands for the first time.
SYNC_PASSWORD
you set in your env vars./ping
to make sure it's working! Enjoy!You only need to run the bot locally if you plan to develop new commands for the bot.
This is because $space push
-ing each time would make development take forever.
$cd <folder>
$python -m venv venv
$source venv/bin/activate
$pip install -r requirements.txt
$deactivate
. example.env
to .env
file and update its contents.
$space dev
to start both main
and bot
micros.https://localhost
can't be accessed by Discord.
space reverse proxy
and the URL is your micro's URL: https://<name>-1-a1234567.deta.app
space link
to switch to a test space app.ngrok http 4200
to get a URL like https://a1b2-34-567-890-123.ngrok-free.app
.cloudflared tunnel --url https://localhost:4200
to get a URL like https://ab-quick-brown-fox.trycloudflare.com
.CTRL+C
to stop them.Interactions Endpoint URL
to <url>/interactions
.
https://discord.com/developers/applications/{application_id}/information
https://<name>-1-a1234567.deta.app
--reload
so any edits you make automatically restarts the webserver.CTRL+C
.When you're ready, you can run $space push
to update the space app.