问题
Basically I'm making this lyrics command, and many times, the amount of characters in a lyric for most songs exceed 2000 characters, which is passed Discord's limit. I wonder how I would go about making it send 2 different messages at once.
I'm wondering how I could make it send the first 2000 characters in one message, then send the remaining characters in a second message right after.
Here is my code right here:
if (message.content.startsWith(config.prefix + `lyrics`)) {
var artistTitle = getArtistTitle(serverQueue.songs[0].title)
console.log(artistTitle)
lyrics.get(artistTitle[0], artistTitle[1], function(err, res){
if(err){
return message.channel.send({embed: {
title: `:x: | Oops! I have encountered an error!`,
description: err,
color: 0xDE2E43
}})
console.log(err);
}
else{
return message.channel.send({embed: {
title: `Lyrics for ${serverQueue.songs[0].title}. Requested by ${message.author.username}`,
description: res,
footer: {
icon_url: serverQueue.songs[0].thumbnail,
text: `Powered by lyrics.wikia.com`
}
}})
}
});
}
回答1:
You can use substring to cut the message up:
for(let i = 0; i < str.length; i += 2000) {
const toSend = str.substring(i, Math.min(str.length, i + 2000));
sendMessage(toSend);
}
来源:https://stackoverflow.com/questions/49205298/sending-2-different-messages-if-message-exceeds-2000-characters