我有一条消息,可以说大约2k个字符,所以我如何分割消息,以便它将消息分段发送
示例“帮助”命令超过2000个字符
if (!args[0]) {
// Load guild settings (for prefixes and eventually per-guild tweaks)
const settings = message.settings;
// Filter all commands by which are available for the user's level, using the <Collection>.filter() method.
const myCommands = message.guild ? client.commands.filter(cmd => client.levelCache[cmd.conf.permLevel] <= level) : client.commands.filter(cmd => client.levelCache[cmd.conf.permLevel] <= level && cmd.conf.guildOnly !== true);
// Here we have to get the command names only, and we use that array to get the longest name.
// This make the help commands "aligned" in the output.
const commandNames = myCommands.keyArray();
const longest = commandNames.reduce((long, str) => Math.max(long, str.length), 0);
let currentCategory = "";
let output = `= Command List =\n\n[Use ${settings.prefix}help <commandname> for details]\n`;
const sorted = myCommands.array().sort((p, c) => p.help.category > c.help.category ? 1 : p.help.name > c.help.name && p.help.category === c.help.category ? 1 : -1 );
sorted.forEach( c => {
const cat = c.help.category.toProperCase();
if (currentCategory !== cat) {
output += `\n== ${cat} ==\n`;
currentCategory = cat;
}
output += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
});
message.channel.send(output, {code:"asciidoc"});
} else {
// Show individual command's help.
let command = args[0];
if (client.commands.has(command)) {
command = client.commands.get(command);
if (level < client.levelCache[command.conf.permLevel]) return;
message.channel.send(`= ${command.help.name} = \n${command.help.description}\nusage::${command.help.usage}`, {code:"asciidoc"});
}
}
任何简单的邮件拆分方法
我看到了https://stackoverflow.com/a/52863304/12843955的东西,但是没有得到
答案 0 :(得分:0)
我尝试了
let output = `= Command List =\n\n[Use ${settings.prefix}help <commandname> for details]\n`;
let output1 =`` , output2 = ``;
if (output.length < 1900 ) output += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
else if (output.length > 1900){
output1 += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
}
else if(output1.length >1900 && output.length > 1900 ) output2 += `${settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
message.channel.send(output, {code:"asciidoc"});
if(output1 !== ``) message.channel.send(output1, {code:"asciidoc"});
if(output2 !== ``) message.channel.send(output2, {code:"asciidoc"});
及其可行的解决方案,但是还有比这更好的解决方案吗?