Skip to content

Parhlai/discord-studybot

Repository files navigation

Discord Ping-Pong Bot

A simple Discord bot that responds to /ping commands with "pong". Built with Cloudflare Workers.

Prerequisites

  • Node.js v16+
  • Discord Application with Bot Token
  • Cloudflare Workers account
  • ngrok account (for local development)

Getting Discord Tokens

  1. Go to the Discord Developer Portal
  2. Create a new application or select an existing one
  3. Go to the "Bot" section and create a bot
  4. Copy the Bot Token (this is your DISCORD_TOKEN)
  5. Go to "General Information" and copy the Application ID (this is your DISCORD_APPLICATION_ID)
  6. In the "Bot" section, ensure the bot has the applications.commands scope

Setting up ngrok

  1. Sign up for a free account at ngrok.com
  2. Install ngrok:
    • Linux/macOS: curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
    • Or download directly: Download from ngrok downloads
  3. Connect your account: ngrok config add-authtoken <your_authtoken>

Setup

  1. Install dependencies:
npm install
  1. Set environment variables for local development:
export DISCORD_TOKEN=your_bot_token
export DISCORD_APPLICATION_ID=your_application_id
  1. Add secrets to Cloudflare Workers:
npx wrangler secret put DISCORD_TOKEN
npx wrangler secret put DISCORD_APPLICATION_ID
npx wrangler secret put DISCORD_PUBLIC_KEY
  1. Register the slash command:
node src/register.js

Development

Start local development server:

npm run dev

For local testing with Discord, use ngrok to expose your local server:

npm run ngrok

Update your Discord application's Interactions Endpoint URL with the ngrok HTTPS URL.

Deployment

Deploy to Cloudflare Workers:

npm run deploy

Update your Discord application's Interactions Endpoint URL with your Cloudflare Worker URL.

Usage

  • /ping - Bot responds with "pong"

Project Structure

  • src/commands.js - Command definitions
  • src/server.js - Main bot logic and request handling
  • src/register.js - Command registration script

About

AI based discord study bot made for r/NUST.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages