Skip to main content

TypeScript (discord.js + express)

Clean Webhook integration structured using TypeScript.

import { Client, GatewayIntentBits, EmbedBuilder, TextChannel } from 'discord.js';
import express, { Request, Response } from 'express';
import fetch from 'node-fetch';

const config = {
DISCORD_TOKEN: "YOUR_BOT_TOKEN",
Botliy_API_TOKEN: "YOUR_Botliy_API_TOKEN",
BOT_ID: "YOUR_BOT_ID",
WEBHOOK_SECRET: "your_webhook_secret_here",
VOTE_CHANNEL_ID: "123456789012345678"
};

const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const app = express();
app.use(express.json());

app.post('/Botliy/webhook', async (req: Request, res: Response) => {
if (req.headers.authorization !== config.WEBHOOK_SECRET) {
return res.status(401).send("Unauthorized");
}

const { bot, user, type } = req.body;
const channel = client.channels.cache.get(config.VOTE_CHANNEL_ID) as TextChannel;

if (channel) {
const embed = new EmbedBuilder()
.setTitle("🎉 New Vote Received!")
.setDescription(`<@${user}> just voted for the bot!\n\nThank you!`)
.setColor(0x5865F2);

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

res.status(200).send("OK");
});

client.once('ready', () => {
app.listen(8999);
setInterval(async () => {
await fetch(`https://Botliy.online/api/bots/${config.BOT_ID}/stats`, {
method: 'POST',
headers: { 'Authorization': config.Botliy_API_TOKEN, 'Content-Type': 'application/json' },
body: JSON.stringify({ server_count: client.guilds.cache.size, shard_count: 1 })
});
}, 1800000);
});

client.login(config.DISCORD_TOKEN);