Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

javascript - discordjs message.guild.roles.size returns null in serverinfo command

It might be new to Discord.js v12. I've upgraded from v11 to v12 and I found out my serverinfo total roles returned null.

Source for roles part:

.addField("Role Count:", `${message.guild.roles.size}`, true)

cmd did not return an error.

I checked guild.roles in https://discordjs.guide/additional-info/changes-in-v12.html#collection but I didn't understand what it means by Manager:

guild.roles is now a Manager instead of a Collection

question from:https://stackoverflow.com/questions/65626823/discordjs-message-guild-roles-size-returns-null-in-serverinfo-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Although you did your research, you missed that it mentions on the top of the page that v12 introduces the concept of managers, you will no longer be able to directly use collection methods. https://discordjs.guide/additional-info/changes-in-v12.html#managers-cache

You will now have to directly ask for cache on a manager before trying to use collection methods:

.addField("Role Count:", `${message.guild.roles.cache.size}`, true)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...