WebhooksNotificationsEmbeds4 min read

Configure and use Discord Webhooks

Create webhooks, send messages and embeds, set up notifications and server monitoring alerts.


What are Webhooks?

Webhooks allow you to send messages to a Discord channel without needing a bot online. They are ideal for notifications, server alerts, external service integration and logging.

Step 1: Create a webhook

From Discord

  1. Go to Channel SettingsIntegrationsWebhooks
  2. Click New Webhook
  3. Configure name and avatar
  4. Copy the webhook URL

From code

javascript
const webhook = await channel.createWebhook({
  name: 'Server Alerts',
  avatar: 'https://your-domain.com/avatar.png'
});
console.log(`Webhook created: ${webhook.url}`);

Step 2: Send simple messages

bash
# From bash (ideal for monitoring scripts)
curl -H "Content-Type: application/json" \
  -d '{"content": "Deploy completed successfully"}' \
  "https://discord.com/api/webhooks/ID/TOKEN"
javascript
// From Node.js
const { WebhookClient } = require('discord.js');

const webhook = new WebhookClient({ url: process.env.WEBHOOK_URL });

await webhook.send({
  content: 'Simple message from webhook'
});

Step 3: Send embeds

javascript
const { EmbedBuilder } = require('discord.js');

const embed = new EmbedBuilder()
  .setTitle('Server Status')
  .setColor(0x00ff00)
  .addFields(
    { name: 'CPU', value: '23%', inline: true },
    { name: 'RAM', value: '1.2/4 GB', inline: true },
    { name: 'Uptime', value: '15 days', inline: true }
  )
  .setTimestamp();

await webhook.send({ embeds: [embed] });

Step 4: VPS monitoring alerts

Script to send alerts when resources are high:

bash
#!/bin/bash
# /opt/scripts/server-alert.sh
WEBHOOK="https://discord.com/api/webhooks/ID/TOKEN"

CPU=$(top -bn1 | grep 'Cpu(s)' | awk '{print $2}')
RAM=$(free -m | awk '/Mem:/ {printf "%.1f", $3/$2*100}')
DISK=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')

if (( $(echo "$CPU > 80" | bc -l) )); then
  curl -s -H "Content-Type: application/json" \
    -d "{\"content\": \"Warning: **High CPU:** ${CPU}%\"}" "$WEBHOOK"
fi

if (( $(echo "$RAM > 85" | bc -l) )); then
  curl -s -H "Content-Type: application/json" \
    -d "{\"content\": \"Warning: **High RAM:** ${RAM}%\"}" "$WEBHOOK"
fi

Step 5: GitHub integration

In your repository → SettingsWebhooks → add the Discord webhook URL with /github at the end:

terminal
https://discord.com/api/webhooks/ID/TOKEN/github

You'll receive notifications for pushes, PRs and issues directly in Discord.

Recommendations

  • Store webhook URLs in environment variables
  • Use webhooks for alerts and notifications, not for interaction
  • Limit sending frequency to avoid flooding the channel
  • Rotate webhooks if you suspect the URL was exposed

Was this guide helpful?