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

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

实际上,我不知道如何修复我的代码,我尝试了很多,但我仍然无法解决问题

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);

您可以从 message.guild.roles.cache.array() 更改为 [...message.guild.roles.cache.values()]

docs 是这样说的:

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