Skip to content

YourGPT/custom-discord-server

Repository files navigation

YourGPT Discord Bot

A self-hosted Discord gateway bot that connects your Discord server to your YourGPT chatbot using Ping Mode.

When a user sends a message (via @mention or in a monitored channel), this bot securely forwards it to YourGPT — which then generates a response and sends it back through Discord.


Prerequisites

Before you begin, make sure you have:


Quick Start

# 1. Clone or download this project
git clone https://github.com/YourGPT/custom-discord-server.git
cd custom-discord-server

# 2. Install dependencies
npm install

# 3. Set up your environment
cp .env.example .env
# Open .env and fill in your values (see Configuration below)

# 4. Start the bot
npm start

Step 1 — Create a Discord Bot

1.1 — Create a new application

  1. Go to Discord Developer Portal
  2. Click New Application → give it a name → click Create

1.2 — Get your Bot Token and enable Intents

  1. Go to the Bot section in the left sidebar
  2. Click Reset Token → confirm → copy the token
  3. Scroll down to Privileged Gateway Intents and enable:
    • MESSAGE CONTENT INTENTCritical. Without this the bot cannot read messages and will appear online but never respond.
  4. Click Save Changes

Keep your token private. If it is ever exposed, reset it immediately from this page.

1.3 — Invite the bot to your server

  1. Go to OAuth2 → URL Generator in the left sidebar

  2. Under Scopes, check bot

  3. Under Bot Permissions, check Administrator

  4. Copy the generated URL at the bottom → open it in your browser → select your server → click Authorise


Step 2 — Enable Ping Mode in YourGPT

  1. Open your YourGPT Dashboard

  2. Go to Chatbot → Integrations → Discord

  3. Select Custom Bot and enter your bot token → click Enable

  4. Scroll to the Ping Mode section and toggle it ON

  5. From this section, copy:

    • Webhook URL → paste into YOURGPT_PING_WEBHOOK_URL in your .env
    • Webhook Secret → paste into YOURGPT_PING_WEBHOOK_SECRET in your .env
  6. Set your Trigger preference:

    • @ Mention Bot → bot responds only when @mentioned
    • Direct Message → bot responds to all messages in monitored channels
  7. Optionally enter Channel IDs to restrict which channels the bot monitors


Step 3 — Configure Your .env

Open the .env file and fill in your values:

DISCORD_BOT_TOKEN=your_discord_bot_token_here
YOURGPT_PING_WEBHOOK_URL=https://api.yourgpt.ai/chatbot/v1/discord/pingWebhook/YOUR_APPLICATION_ID
YOURGPT_PING_WEBHOOK_SECRET=ygpt_whsec_xxxxxxxx
Variable Description
DISCORD_BOT_TOKEN Your bot token from Step 1.2
YOURGPT_PING_WEBHOOK_URL Webhook URL copied from Step 2
YOURGPT_PING_WEBHOOK_SECRET Webhook secret copied from Step 2

Trigger and Reply Settings

The Trigger and Reply Mode are configured entirely from your YourGPT dashboard — no changes needed in the bot code or .env file.

  • @ Mention Bot — bot responds only when a user @mentions it. Best for public channels.
  • Direct Message — bot responds to every message in monitored channels. Best for dedicated support channels.
  • Reply in Thread — bot creates a new thread per conversation, keeping the main channel clean.
  • Reply in Normal Chat — bot replies directly in the channel.

Running the Bot

Option 1 — Direct (Development)

npm start

Option 2 — PM2 (Recommended for Production)

PM2 keeps the bot running in the background and automatically restarts it if it crashes.

# Install PM2 globally (one-time setup)
npm install -g pm2

# Start the bot
pm2 start ecosystem.config.js

# View live logs
pm2 logs yourgpt-discord-bot

# Stop the bot
pm2 stop yourgpt-discord-bot

# Restart the bot
pm2 restart yourgpt-discord-bot

# Auto-start on server reboot (run once after first start)
pm2 startup
pm2 save

Option 3 — Docker

# Build and start
docker compose up -d

# View live logs
docker compose logs -f

# Stop
docker compose down

Troubleshooting

Bot is online but does not respond to messages

  1. Check MESSAGE CONTENT INTENT — This is the most common cause. Go to Discord Developer Portal → your app → Bot → enable MESSAGE CONTENT INTENT → Save Changes.

  2. Check your Trigger setting in YourGPT dashboard Go to Discord integration → Custom Bot → Ping Mode and confirm the Trigger is set to the mode you expect (@ Mention Bot or Direct Message).

  3. Check bot permissions in your channel Make sure you granted the bot Administrator permission when inviting it (Step 1.4).

  4. Check Channel IDs (if configured) If you added Channel IDs in YourGPT dashboard, make sure you are messaging in one of those channels. To get a channel ID: right-click the channel in Discord → Copy Channel ID (requires Developer Mode enabled in Discord settings).


401 Unauthorized error in logs

Your YOURGPT_PING_WEBHOOK_SECRET is wrong. Copy it again from the YourGPT dashboard Ping Mode section.

404 Not Found error in logs

Either your YOURGPT_PING_WEBHOOK_URL is wrong, or Ping Mode is not enabled in the YourGPT dashboard. Check both.

Bot login failed / TokenInvalid

Your DISCORD_BOT_TOKEN is invalid. Go to the Discord Developer Portal → BotReset Token and paste the new value into your .env.


Security Notes

  • Never commit your .env file to Git — it is already in .gitignore
  • If your YOURGPT_PING_WEBHOOK_SECRET is ever exposed, regenerate it by toggling Ping Mode off then on in the YourGPT dashboard, then update your .env
  • Run this bot on a trusted private server, not on a shared hosting environment

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors