1

I am making a role list command but turns out I have too many roles. Anyway to split the message into more. The roles are stored in an array. Btw I only want roles starting with A.

const roles = message.guild.roles.cache.filter(c => c.name.startsWith('A'))

Here is the error in console

Invalid Form Body content: Must be 2000 or fewer in length.
module.exports = {
    name: 'rolelist',
    description: 'Sends A List Of Roles Availible In The Server',
    execute(message, args, client) {
        if (!message.content.startsWith(prefix) || message.author.bot) return;
        const roles = message.guild.roles.cache.filter(c => c.name.startsWith('A'))
        if (colors.size < 1) {
            return message.channel.send('There are no roles starting with the letter A');
        }
        message.channel.send(roles.array().join(` \n`), {split:true,})
    },
};

TalentYT
  • 97
  • 2
  • 12

1 Answers1

2

Accoding to the docs you can split the messages:

.send(data, { split: true })

If you weren't already aware, .send() takes 2 parameters: the content to send, and the message options to pass in. You can read about the MessageOptions type here. Using split: true here will automatically split our help message into 2 or more messages in the case that it exceeds the 2,000 character limit.

https://discordjs.guide/command-handling/adding-features.html#a-dynamic-help-command

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
  • It looks like you need to add at least one `\n`, https://discord.js.org/#/docs/main/stable/typedef/SplitOptions what on earth are you sending? – Lawrence Cherone Sep 09 '20 at 11:06
  • Its in the utils class, which you could import: https://github.com/discordjs/discord.js/blob/b38f537da89e02d7cce0af508cd07d284e2fa8ec/src/util/Util.js#L56 though you could just do it yourself by [splitting the string](https://stackoverflow.com/questions/7033639/split-large-string-in-n-size-chunks-in-javascript) and sending multiple messages. Though it seems odd that your list has no newlines, how are you generating it and what format is it? its not simply JSON.stringify() is it? – Lawrence Cherone Sep 09 '20 at 11:29
  • I not sure, you might need open a new question for the mentions issue, you might be able to use backticks to wrap the roles so the `@` is escaped: '\`'+roles.array().join('\` \n')+'\`' – Lawrence Cherone Sep 09 '20 at 11:45