【问题标题】:Sending 2 different messages if message exceeds 2000 characters如果消息超过 2000 个字符,则发送 2 条不同的消息
【发布时间】:2018-08-18 16:57:08
【问题描述】:

基本上我在做这个歌词命令,而且很多时候,大多数歌曲的歌词中的字符数超过了 2000 个字符,这超过了 Discord 的限制。我想知道如何让它一次发送 2 条不同的消息。

我想知道如何让它在一条消息中发送前 2000 个字符,然后在第二条消息中发送剩余的字符。

这是我的代码:

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`
                    }
                }})
            }
        });
    }

【问题讨论】:

  • 这是我现在的代码pastebin.com/j6bbF4TB
  • 请将您的相关代码添加到问题中,而不仅仅是在 pastebin 链接中
  • 从您 pastebin 上的代码来看,您似乎想将所有歌词文本作为 embed 发送?
  • 是的,当字符数超过 2000 时,我想发送 2 个不同的嵌入

标签: javascript node.js discord discord.js


【解决方案1】:

您可以使用子字符串来分割消息:

for(let i = 0; i < str.length; i += 2000) {
    const toSend = str.substring(i, Math.min(str.length, i + 2000));
    sendMessage(toSend);
}

【讨论】:

  • 我会试试这个
  • @FreezIn 如果我有帮助,请确保将我的答案标记为正确 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-27
  • 1970-01-01
  • 2013-08-20
  • 1970-01-01
  • 2019-02-20
  • 2017-09-17
  • 2012-08-01
相关资源
最近更新 更多