简体   繁体   English

从 v11 迁移后,无法在 discord.js v12 中从服务器设置用户状态和记录用户数量

[英]Cant set user status and log user amount from server in discord.js v12 after migrating from v11

Confusing question i know right, but im having this issue after migrating from discord.js v11 to v12 with a bot for my friend.我知道的令人困惑的问题是正确的,但是在使用我朋友的机器人从 discord.js v11 迁移到 v12 后,我遇到了这个问题。

Im having trouble with getting the amount of user(s) in a server,我无法获取服务器中的用户数量,

Original Code (v11):原始代码(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"
        }
    }); 
});

Starting bot on v12 throws this error: "size" is not defined"在 v12 上启动机器人会引发此错误: "size" is not defined"

So in my console i get "bot has started with undefined users in undefined channels" after migrating to v12, in v11, i'd normally get "Bot has started with (12) users in (x) channels"因此,在我的控制台中,在迁移到 v12 后,我得到“机器人已在未定义的频道中使用未定义的用户开始”,在 v11 中,我通常会得到“机器人已在 (x) 频道中使用 (12) 个用户开始”

I just made a migration and had the same problem.我刚刚进行了迁移并遇到了同样的问题。

You have to replace:你必须更换:

client.users.size

by经过

client.users.cache.size

Add also .cache before .channels and .guilds for your other variables..channels.cache之前为您的其他变量添加.guilds

You can read the documentation here: https://discordjs.guide/additional-info/changes-in-v12.html#managers-cache您可以在此处阅读文档: https://discordjs.guide/additional-info/changes-in-v12.html#managers-cache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM