WebhooksNotificacionesEmbeds4 min de lectura

Configurar y usar Webhooks de Discord

Crear webhooks, enviar mensajes y embeds, configurar notificaciones y alertas de servidor.


¿Qué son los Webhooks?

Los webhooks permiten enviar mensajes a un canal de Discord sin necesidad de un bot online. Son ideales para notificaciones, alertas de servidor, integración con servicios externos y logging.

Paso 1: Crear un webhook

Desde Discord

  1. Andá a Configuración del canalIntegracionesWebhooks
  2. Hacé clic en Nuevo Webhook
  3. Configurá nombre y avatar
  4. Copiá la URL del webhook

Desde código

javascript
const webhook = await channel.createWebhook({
  name: 'Alertas del Servidor',
  avatar: 'https://tu-dominio.com/avatar.png'
});
console.log(`Webhook creado: ${webhook.url}`);

Paso 2: Enviar mensajes simples

bash
# Desde bash (ideal para scripts de monitoreo)
curl -H "Content-Type: application/json" \
  -d '{"content": "✅ Deploy completado exitosamente"}' \
  "https://discord.com/api/webhooks/ID/TOKEN"
javascript
// Desde Node.js
const { WebhookClient } = require('discord.js');

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

await webhook.send({
  content: 'Mensaje simple desde webhook'
});

Paso 3: Enviar embeds

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

const embed = new EmbedBuilder()
  .setTitle('Estado del Servidor')
  .setColor(0x00ff00)
  .addFields(
    { name: 'CPU', value: '23%', inline: true },
    { name: 'RAM', value: '1.2/4 GB', inline: true },
    { name: 'Uptime', value: '15 días', inline: true }
  )
  .setTimestamp();

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

Paso 4: Alertas de monitoreo del VPS

Script para enviar alertas cuando los recursos están altos:

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\": \"⚠️ **CPU alta:** ${CPU}%\"}" "$WEBHOOK"
fi

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

Paso 5: Integración con GitHub

En tu repositorio → SettingsWebhooks → agregá la URL del webhook de Discord con /github al final:

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

Recibís notificaciones de pushes, PRs y issues directamente en Discord.

Recomendaciones

  • Guardá las URLs de webhooks en variables de entorno
  • Usá webhooks para alertas y notificaciones, no para interacción
  • Limitá la frecuencia de envío para no saturar el canal
  • Rotá los webhooks si sospechás que la URL fue expuesta

¿Te resultó útil esta guía?