如果消息超过2000个字符,则发送2条不同的消息 [英] Sending 2 different messages if message exceeds 2000 characters
本文介绍了如果消息超过2000个字符,则发送2条不同的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我正在执行此歌词命令,而且很多歌曲的歌词中的字符数量经常超过2000个字符,这已超过Discord的限制。我想知道如何使它一次发送2条不同的消息。
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.
我想知道如何使其在一条消息中发送前2000个字符,然后
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.
这是我的代码在这里:
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`
}
}})
}
});
}
推荐答案
您可以使用子字符串来剪切消息向上:
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);
}
这篇关于如果消息超过2000个字符,则发送2条不同的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文