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.
Before you begin, make sure you have:
- Node.js v18 or higher — Download
- A Discord bot application — Create one here
- A YourGPT account with Discord integration configured — Dashboard
# 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- Go to Discord Developer Portal
- Click New Application → give it a name → click Create
- Go to the Bot section in the left sidebar
- Click Reset Token → confirm → copy the token
- Scroll down to Privileged Gateway Intents and enable:
- MESSAGE CONTENT INTENT ← Critical. Without this the bot cannot read messages and will appear online but never respond.
- Click Save Changes
Keep your token private. If it is ever exposed, reset it immediately from this page.
-
Go to OAuth2 → URL Generator in the left sidebar
-
Under Scopes, check
bot -
Under Bot Permissions, check
Administrator -
Copy the generated URL at the bottom → open it in your browser → select your server → click Authorise
-
Open your YourGPT Dashboard
-
Go to Chatbot → Integrations → Discord
-
Select Custom Bot and enter your bot token → click Enable
-
Scroll to the Ping Mode section and toggle it ON
-
From this section, copy:
- Webhook URL → paste into
YOURGPT_PING_WEBHOOK_URLin your.env - Webhook Secret → paste into
YOURGPT_PING_WEBHOOK_SECRETin your.env
- Webhook URL → paste into
-
Set your Trigger preference:
- @ Mention Bot → bot responds only when @mentioned
- Direct Message → bot responds to all messages in monitored channels
-
Optionally enter Channel IDs to restrict which channels the bot monitors
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 |
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.
npm startPM2 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# Build and start
docker compose up -d
# View live logs
docker compose logs -f
# Stop
docker compose down-
Check
MESSAGE CONTENT INTENT— This is the most common cause. Go to Discord Developer Portal → your app → Bot → enable MESSAGE CONTENT INTENT → Save Changes. -
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).
-
Check bot permissions in your channel Make sure you granted the bot Administrator permission when inviting it (Step 1.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).
Your YOURGPT_PING_WEBHOOK_SECRET is wrong. Copy it again from the YourGPT dashboard Ping Mode section.
Either your YOURGPT_PING_WEBHOOK_URL is wrong, or Ping Mode is not enabled in the YourGPT dashboard. Check both.
Your DISCORD_BOT_TOKEN is invalid. Go to the Discord Developer Portal → Bot → Reset Token and paste the new value into your .env.
- Never commit your
.envfile to Git — it is already in.gitignore - If your
YOURGPT_PING_WEBHOOK_SECRETis 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
MIT