Ryo is a Discord bot that uses the Discord Interactions API to respond to slash commands. It's built using Hono for Cloudflare Workers, which allows you to run serverless functions at the edge of Cloudflare's network.
- Slash commands
- Reddit Hot Posts from a Subreddit
- Forwards Email to Discord using Cloudflare Email Routing
Before starting, you'll need a Discord app with the following permissions:
bot
with theSend Messages
andUse Slash Command
permissionsapplications.commands
scope
⚙️ Permissions can be configured by clicking on the
OAuth2
tab and using theURL Generator
. After a URL is generated, you can install the app by pasting that URL into your browser and following the installation flow.
This bot also has the ability to forward emails to a Discord channel. The worker will be registered as an Email Routing rule in Cloudflare. When an email is sent to the custom email address, it will be forwarded to the Discord channel using the Webhook URL (how to get Webhook URL [Doc])
Prerequisites:
Setup:
- Adding Webhook URL as Secret
- Using Wrangler CLI
Paste Webhook URL
wrangler secret put DISCORD_WEBHOOK_URL
? Enter a secret value: ›
- Setting Worker as a rule for custom address
- In Cloudflare dashboard go to Email > Email Routing > Routes.
- Select Create address.
- In Custom address, enter the custom email address you want to use (for example, 'ryo').
- In the Action drop-down menu, choose "send to worker"
- Select "ryo" as the destination
git clone https://github.com/radityaharya/ryo.git
cd ryo
To install the dependencies, run the following command:
npm install
Set up your environment variables by creating a .env
file in the root of the project. You can use the example.env
file as a template.
To deploy the app, you'll need to install the Wrangler CLI. Once installed, you can deploy the app using the following command:
wrangler deploy
The credentials in .env
are only applied locally. The production service needs access to credentials from your app:
wrangler secret put DISCORD_TOKEN
wrangler secret put DISCORD_PUBLIC_KEY
wrangler secret put DISCORD_APPLICATION_ID
wrangler secret put DISCORD_WEBHOOK_URL
wrangler secret put BOT_SECRET
After deploying the app, you'll need to register the bot with Discord. You can do this by inputting your interactions
URL into the Interactions Endpoint URL
field in the General Information
tab of the Discord Developer Portal.
Registering Commands
Commands should be registered with Discord using the register
command after the bot has been deployed or when commands are updated.
npm run register