discord - 超过 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,})
},
};
解决方案
根据文档,您可以拆分消息:
.send(data, { split: true })
如果您还不知道,.send() 采用 2 个参数:要发送的内容和要传入的消息选项。您可以在此处阅读有关 MessageOptions 类型的信息。在此处使用 split: true 将自动将我们的帮助消息拆分为 2 条或更多条消息,以防超过 2,000 个字符的限制。
https://discordjs.guide/command-handling/adding-features.html#a-dynamic-help-command
推荐阅读
- mongodb - nodemon] 应用程序崩溃 - 启动前等待文件更改
- go - 使用日志包附加到当前行
- algorithm - 这种贪心算法能更高效吗?
- powershell - 要显示的 powershell 变量值的一部分
- sql - 在数据库的所有现有表中搜索数据
- python - 我有一个状态表,但我希望它每 10 分钟更改一次状态。我正在使用 Postgresql
- r - ifelse R中一系列列的多个OR条件
- javascript - 如果我使用一个端点监视另一个端点,这是不好的做法吗?
- python - 将 Python Ray 与 CPLEX 模型对象结合使用
- c++ - 如何查找向量的元素是否交替为符号?