Is it possible to import my Discord's bot info (number of guilds it is in, etc) on my HTML website?

Viewed 44

I'm making a website for my Discord bot and I'd like to import some info regarding the bot on the website.

Is it possible? If yes, how?

The website is in HTML and is not hosted server as the bot.

1 Answers

You can make some sort of API using express (or an other webserver module like fastify) and setup routes to retreive data.

Quick example:

const express = require('express');
const { Client } = require('discord.js');
const app = express();
const client = new Client();
// enable cors
const cors = require('cors');
app.use(cors());

client.on('ready', () => {
app.get("/userCount", (req, res) => {
res.send(client.users.cache.size);
});

app.get("/guildCount", (req, res) => {
res.send(client.guilds.cache.size);
});
});

app.listen(3000);
client.login("supersecrettoken");

To get guild count on your webpage:

fetch("http://localhost:3000/guildCount").then(res => {
res.text().then(guildCount => {
console.log(guildCount); // will log the number of guilds
});
});

Hope this helps!

Related