Sending 2 different messages if message exceeds 2000 characters

烈酒焚心 提交于 2020-07-08 03:51:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!