[英]Cant set user status and log user amount from server in discord.js v12 after migrating from v11
我知道的令人困惑的問題是正確的,但是在使用我朋友的機器人從 discord.js v11 遷移到 v12 后,我遇到了這個問題。
我無法獲取服務器中的用戶數量,
原始代碼(v11):
client.on("ready", () => {
console.log(`jthefibot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} servers.`);
client.user.setPresence({
status: "online",
game: {
name: `jt.help for commands | Watching over the jTheFifthElement server with ${client.users.size} members.`,
type: "Watching"
}
});
});
在 v12 上啟動機器人會引發此錯誤: "size" is not defined"
因此,在我的控制台中,在遷移到 v12 后,我得到“機器人已在未定義的頻道中使用未定義的用戶開始”,在 v11 中,我通常會得到“機器人已在 (x) 頻道中使用 (12) 個用戶開始”
我剛剛進行了遷移並遇到了同樣的問題。
你必須更換:
client.users.size
經過
client.users.cache.size
在.channels
和.cache
之前為您的其他變量添加.guilds
。
您可以在此處閱讀文檔: https://discordjs.guide/additional-info/changes-in-v12.html#managers-cache
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.