Confusing question i know right, but im having this issue after migrating from discord.js v11 to v12 with a bot for my friend.
Im having trouble with getting the amount of user(s) in a server,
Original Code (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"
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"
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.
You can read the documentation here: https://discordjs.guide/additional-info/changes-in-v12.html#managers-cache
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.