Shorten the list of the guild's roles list

Viewed 176

In my serverinfo command, I have a part where the bot list all the roles in that the guild has. However, when the guild has a very large amount of roles it gives me the error embed.fields[3].value: Must be 1024 or fewer in length. I'm not quite sure how the bot will only send the first six roles in the list then rest as `...[number] more roles. v12.2

${message.guild.roles.cache.map(r => `${r}`).join(" ").replace("@everyone", " ")}
1 Answers

It's simple, you can use .array() method to get an array with all roles and just slice that array.

"[number] more roles" you can do this just removing 6 of guild roles size

Here is a example:

message.guild.roles.cache.array().slice(0,6).map(role => `${role}`).join(" ").replace("@everyone", " ") + (message.guild.roles.cache.size - 6 > 0 ? " and more " + (message.guild.roles.cache.size - 6) + " roles." : "")

Worked fine for me.

Related