【问题标题】:Split Message of More than 2000 characters Discord.js超过 2000 个字符的拆分消息 Discord.js
【发布时间】:2020-12-27 18:44:54
【问题描述】:

我正在创建角色列表命令,但结果发现我的角色太多。无论如何,将消息拆分为更多。角色存储在一个数组中。顺便说一句,我只想要以 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,})
    },
};

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

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

    .send(data, { split: true })

    如果您还不知道,.send() 有 2 个参数:内容 要发送,以及要传递的消息选项。您可以阅读有关 MessageOptions 类型 here。使用 split: true 这里会自动 将我们的帮助消息分成 2 条或更多条消息,以防万一 超过 2,000 个字符的限制。

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

    【讨论】:

    • 看来您至少需要添加一个\ndiscord.js.org/#/docs/main/stable/typedef/SplitOptions 您到底要发送什么?
    • 它在 utils 类中,您可以导入:github.com/discordjs/discord.js/blob/… 尽管您可以通过 splitting the string 自己完成并发送多条消息。尽管您的列表没有换行符似乎很奇怪,但您是如何生成它的,它是什么格式?它不只是 JSON.stringify() 是吗?
    • 我不确定,您可能需要针对提及问题打开一个新问题,您可能可以使用反引号来包装角色,以便转义 @:'`'+roles.array ().join('` \n')+'`'
    猜你喜欢
    • 1970-01-01
    • 2018-08-18
    • 2021-01-30
    • 1970-01-01
    • 2017-09-22
    • 2020-07-22
    • 2017-02-03
    • 2019-05-06
    • 1970-01-01
    相关资源
    最近更新 更多