如何解决分割超过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个参数:content 发送,以及传递消息选项。您可以阅读有关 MessageOptions类型为here。使用split:true会自动 将我们的帮助消息分为2条或更多消息 超过了2,000个字符的限制。
https://discordjs.guide/command-handling/adding-features.html#a-dynamic-help-command
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。