簡體   English   中英

是否可以在我的 HTML 網站上導入我的 Discord 機器人信息(它所在的公會數量等)?

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

我正在為我的 Discord 機器人創建一個網站,我想在網站上導入一些關於該機器人的信息。

是否可以? 如果是,如何?

該網站位於 HTML,並且不是作為機器人的托管服務器。

您可以使用express (或其他網絡服務器模塊,如fastify )制作某種 API 並設置路由以檢索數據。

快速示例:

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");

要在您的網頁上獲取公會計數:

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

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM