角色列表中的不和谐内容长度不得超过2000

时间:2020-06-24 22:56:00

标签: node.js discord.js

我知道此错误已解决,但以另一种形式我无法解决我的错误:

    if(msg.content.startsWith(`${prefix}roles`)) {
        const spaces = '                      ';
        const roles = [];
        msg.guild.roles.filter(r => r.name !== '@everyone').forEach(c => {
            let list = roles.push(`${c.name} ${spaces.substring(c.name.length)} ${c.members.size} member`);
            if(c.members.size < 2) roles.push(`${c.name} ${spaces.substring(c.name.length)} ${c.members.size} member`);
            if(c.members.size >= 2) roles.push(`${c.name} ${spaces.substring(c.name.length)} ${c.members.size} members`);
        });
        msg.channel.send(`\`\`\` ${roles.join('\n')} \`\`\``);
    }
});

谢谢。

1 个答案:

答案 0 :(得分:2)

好吧,可能是因为您将每个角色两次推入阵列

在这里:

let list = roles.push(${c.name} ${spaces.substring(c.name.length)} ${c.members.size} member);

再过一次,使用if语句

将其更改为一次后,除非您拥有100个角色,否则它应该进行修复,在这种情况下,您只需在split: true内添加选项message.channel.send

https://discord.js.org/#/docs/main/stable/typedef/MessageOptions

https://discord.js.org/#/docs/main/stable/typedef/SplitOptions

if (msg.content.startsWith(`${prefix}roles`)) {
    const spaces = '                      ';
    const roles = [];
    msg.guild.roles.filter(r => r.name !== '@everyone').forEach(role => {
        let string = `${c.name} ${spaces.substring(c.name.length)} ${c.members.size} member`;

        if (role.members.size >= 2) {
            string += "s";
        }

        roles.push(string);
    });
    //all those escape characters look bad, just concat strings
    msg.channel.send("```\n" + roles.join('\n') + "\n```", { split: true });
}