我正在为一个客户开发一个discord机器人网站,他需要实时统计他的discord机器人在网站上的服务器数量。我不知道discord.js,也找不到一个简单的答案。
这些是我已经做过的事情:
- 添加了node.js中的discord.js
- 在StackOverflow上尝试了多种解决方案(没有一个给我正确答案(
let element = document.getElementById('serverCount')
let serverCount;
// This is where the code to get the discord bot server count should be
// It should be stored on the serverCount
element.textContent = serverCount
<h1 id="container">
Trusted by <b id="serverCount"></b> servers!
</h1>
- 看了很多教程,但都是关于编码discordbot的,但不幸的是,我一点都不懂
您可以通过以下方式获取机器人所在服务器的数量:
await client.guilds.cache.fetch(); // update the chache for accurate info.
let serverCount = client.guilds.cache.size;
client.guilds.cache.size
包含机器人的服务器计数,使用fetch()
检索此值。