Node.js (discord.js + express)
A full working bot example posting stats and receiving webhook events using Node.js.
// npm install discord.js express node-fetch
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const express = require('express');
const fetch = require('node-fetch');
// ================= CONFIG =================
const DISCORD_TOKEN = "YOUR_BOT_TOKEN";
const Botliy_API_TOKEN = "YOUR_Botliy_API_TOKEN";
const BOT_ID = "YOUR_BOT_ID";
const WEBHOOK_SECRET = "your_webhook_secret_here";
const VOTE_CHANNEL_ID = "123456789012345678";
// ==========================================
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const app = express();
app.use(express.json());
// ============ WEBHOOK SERVER ============
app.post('/Botliy/webhook', async (req, res) => {
if (req.headers.authorization !== WEBHOOK_SECRET) {
return res.status(401).send("Unauthorized");
}
const { bot, user, type } = req.body;
const channel = client.channels.cache.get(VOTE_CHANNEL_ID);
if (channel) {
const embed = new EmbedBuilder()
.setTitle("🎉 New Vote Received!")
.setDescription(`<@${user}> just voted for the bot!\n\nThank you for supporting us ❤️`)
.setColor("Blurple")
.addFields(
{ name: "👤 Voter", value: `<@${user}>`, inline: true },
{ name: "⏰ Time", value: `<t:${Math.floor(Date.now() / 1000)}:R>`, inline: true }
)
.setFooter({ text: "Thanks for helping us grow 🚀" })
.setThumbnail(client.user.displayAvatarURL());
await channel.send({ embeds: [embed] });
}
res.status(200).send("OK");
});
// ============ POST STATS INTERVAL ============
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
app.listen(8999, () => console.log('Webhook server running'));
setInterval(async () => {
try {
await fetch(`https://Botliy.online/api/bots/${BOT_ID}/stats`, {
method: 'POST',
headers: {
'Authorization': Botliy_API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({ server_count: client.guilds.cache.size, shard_count: 1 })
});
} catch (e) {
console.error("Error posting stats:", e);
}
}, 1800000); // 30 minutes
});
client.login(DISCORD_TOKEN);