Web simple con un boton central de Verificar.
Cuando el usuario pulsa el boton:
- se registra su IP publica,
- se asocia a su
discordId, - y el bot puede consultarlo por API.
- Node.js 18+
npm install- Copia
.env.examplea.env. - Define:
PORT: puerto del servidorBOT_API_SECRET: secreto que usara tu bot en headerx-bot-secretDISCORD_BOT_TOKEN: token del bot (se usa para enviar mensaje al canal)DISCORD_BOT_ID: ID del bot (opcional, solo informativo en el embed)DISCORD_GUILD_ID: ID del servidor (opcional, informativo en el embed)DISCORD_CHANNEL_ID: ID del canal donde se publicara la verificacionDISCORD_RESULT_CHANNEL_ID: ID del canal donde se enviara el resultado final de verificacionVERIFICATION_BASE_URL: URL base de la web (ej:http://localhost:3000)VERIFY_TRIGGER: comando para pedir verificacion (default:!verificar)DISCORD_WEBHOOK_URL(opcional): fallback por webhook
npm startWeb en http://localhost:3000
Iniciar bot:
npm run bot:startIniciar web + bot a la vez:
npm run start:allUso del bot:
- Un usuario escribe
!verificaro/verificar. - El bot publica un embed en
DISCORD_CHANNEL_ID. - El embed envia su ID de usuario y boton a la web con
?discordId=<id>.
Notas:
- Si
!verificarno responde, usa/verificar(no depende de Message Content intent). - El bot registra automaticamente el slash command al iniciar.
Abre la web con el ID de Discord en query param:
http://localhost:3000/?discordId=123456789012345678
Pulsa el boton Verificar.
-
POST /api/verify- body JSON:
{ "discordId": "123..." } - guarda
{ discordId, ip, verifiedAt }
- body JSON:
-
GET /api/bot/check-user/:discordId- requiere header
x-bot-secret - devuelve si el usuario esta verificado y su IP
- requiere header
-
GET /api/bot/check-ip?ip=1.2.3.4- requiere header
x-bot-secret - devuelve usuarios que verificaron con esa IP
- requiere header
-
GET /api/health- healthcheck publico
Si compartiste el token del bot en texto plano, regenéralo de inmediato en Discord Developer Portal y usa solo el token nuevo en .env.
const result = await fetch(
`http://localhost:3000/api/bot/check-user/${discordUserId}`,
{ headers: { "x-bot-secret": process.env.BOT_API_SECRET } }
);
const data = await result.json();
if (data.verified) {
// Usuario verificado
console.log(data.ip, data.verifiedAt);
} else {
// Pedir al usuario abrir la web y verificar
console.log("No verificado");
}