Cloudflare Worker pricebot using Pyth Network oracle to update Discord bot nicknames with live price data.
- Cron Trigger - Runs every 1 minute
- Fetches Price - Gets price from Pyth Hermes API
- Formats - Dynamic decimal places (BTC: $50000, DOGE: $0.1500)
- Updates - Sets bot nickname in all guilds the bot is in
- Gateway Keepalive - Connects to Discord gateway and stays connected for ~59 seconds to keep bot "online" between cron triggers
- Go to Discord Developer Portal
- Create a new application
- Go to Bot section
- Click Reset Token to get your bot token
- Enable Public Bot (for personal use)
- Under Privileged Gateway Intents, enable:
- Server Members Intent
Generate OAuth2 URL with bot scope:
https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot&permissions=1
Visit that URL to add the bot to your server(s).
Find the price feed ID for your desired asset at Pyth Network Price Feeds.
Example feed IDs:
- BTC:
0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 - ETH:
0xff6147a7b6429c8f3f3e9d0da9a6e7f6c6e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6
Push this code to a new GitHub repository.
- Go to Cloudflare Dashboard
- Navigate to Workers & Pages
- Click Create application → Import a Worker project from GitHub
- Connect your GitHub repo (root directory)
In Cloudflare Workers dashboard, go to your worker → Settings → Variables:
Add the following secrets via wrangler secret put:
# Via Wrangler CLI
wrangler secret put DISCORD_BOT_TOKEN
wrangler secret put PYTH_FEED_ID
wrangler secret put TICKEROr set via dashboard:
DISCORD_BOT_TOKEN- Your Discord bot tokenPYTH_FEED_ID- Pyth price feed ID (e.g.,0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)TICKER- Ticker symbol (e.g.,BTC,ETH,SOL)
Once secrets are configured, Cloudflare will auto-deploy on push to main branch.
Or manually deploy:
npm install
npm run deploy| Price Range | Format | Example |
|---|---|---|
| >= $1000 | No decimals | BTC: $50000 |
| >= $100 | 2 decimals | ETH: $3500.00 |
| >= $1 | 3 decimals | SOL: $150.000 |
| < $1 | 4 decimals | DOGE: $0.1500 |
pythwrangler/
├── src/
│ ├── index.ts # Cron handler
│ ├── pyth.ts # Pyth API fetch
│ ├── discord.ts # Discord API calls
│ └── format.ts # Price formatting
├── wrangler.toml # Cron config
├── package.json
└── tsconfig.json
- Cron Schedule: 1 request per minute
- Daily Requests: ~1,440 per day (well under 100,000/day free tier limit)
- Cost: $0 on Cloudflare Workers free tier - DYOR
npm install
npx wrangler dev --test-scheduled
curl "http://localhost:8787/cdn-cgi/handler/scheduled?cron=*/1+*+*+*+*"MIT