Why does client.guilds.cache.size only say quot;0quot; in my playing status even if it#39;s in 2 servers?(为什么client.guilds.cache.size 只说“0?在我的游戏状态中,即使它在 2 个服务器中?)
问题描述
我见过很多人对 client.guilds.size
有问题,但我改用了最近建议的 client.guilds.cache.size
.在我的播放状态中,它只显示 WATCHING my prefix | 0 servers."
尝试获取成员数和频道数时也会发生同样的情况.
i have seen many people who had trouble with client.guilds.size
but I switched to the recently suggested client.guilds.cache.size
. In my playing status, it only says "WATCHING my prefix | 0 servers."
same happens for trying to fetch the member count and channel count.
let activities = [ `${client.guilds.cache.size} servers`, `${client.channels.cache.size} channels`, `${client.users.cache.size} users` ], i = 0;
setInterval(() => client.user.setActivity(`${prefix}help | ${activities[i ++ % activities.length]}`, { type: "WATCHING"}),`${process.env.INTERVAL}`)
这是我用来实现这一目标的脚本.我已经有一个 Eval 命令,它也返回 2.
This is the script I am using to achieve that. I already have an Eval command, that returns 2 aswell.
我似乎无法以某种方式找到解决方案.我希望你能帮助我,如果你需要什么,请告诉我!
I can't seem to find a solution to this somehow. I hope you can help me, if you need anything, tell me!
推荐答案
你的问题是你的client
在你抓取guilds
集合之前没有登录
Your issue is that your client
has not logged in before you grab the guilds
collection
您需要将该代码放入您的 ready
事件中.
You need to place that code inside your ready
event.
client.on('ready', () => {
let activities = [ `${client.guilds.cache.size} servers`, `${client.channels.cache.size} channels`, `${client.users.cache.size} users` ], i = 0;
setInterval(() => client.user.setActivity(`${prefix}help | ${activities[i ++ % activities.length]}`, { type: "WATCHING"}),`${process.env.INTERVAL}`)
})
这篇关于为什么client.guilds.cache.size 只说“0"?在我的游戏状态中,即使它在 2 个服务器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么client.guilds.cache.size 只说“0"?在我的游


基础教程推荐
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01