首页 > 解决方案 > 超过 2000 个字符的拆分消息 Discord.js

问题描述

我正在制作一个角色列表命令,但结果发现我的角色太多了。无论如何,将消息拆分为更多。角色存储在一个数组中。顺便说一句,我只想要以 A 开头的角色。

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

这是控制台中的错误

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

标签: discorddiscord.js

解决方案


根据文档,您可以拆分消息:

.send(data, { split: true })

如果您还不知道,.send() 采用 2 个参数:要发送的内容和要传入的消息选项。您可以在此处阅读有关 MessageOptions 类型的信息。在此处使用 split: true 将自动将我们的帮助消息拆分为 2 条或更多条消息,以防超过 2,000 个字符的限制。

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


推荐阅读