問題描述
我見過很多人對 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 個服務器中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!