Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
TypeError: message.guild.roles.cache.array is not a function

Actually, I don't know how to fix my code anymore, I tried a lot, but I can't solve the problem yet

const Discord = require("discord.js");
const client = new Discord.Client({ intents: 32767 });
const AsciiTable = require("ascii-data-table").default;
const prefix = "#";

client.on("messageCreate", async(message) => {
    if (!message.guild || !message.channel || message.author.bot) return;
    if(message.content.startsWith(prefix + "roles")) {
        var
            ros = message.guild.roles.cache.size,
            data = [["Rank", "RoleName"]]
            for(let i = 0; i < ros; i++) {
                if(message.guild.roles.cache.array()[i].id !== message.guild.id) {
                    data.push([i,`${message.guild.roles.cache.filter(r => r.position == ros-i).map(r=>r.name)}`])
        }
            }
        let res = AsciiTable.table(data)
        message.channel.send({ content: `**\`\`\`xl\n${res}\`\`\`**` });
    }
});

client.login(process.env.TOKEN);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can change from message.guild.roles.cache.array() to [...message.guild.roles.cache.values()]

Here is what the docs said:

These methods existed to provide access to a cached array of Collection values and keys respectively, which other Collection methods relied on internally. Those other methods have been refactored to no longer rely on cache, so those arrays and these methods have been removed.
You should instead construct an array by spreading the iterators returned by the base Map class methods

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!