Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

javascript - Splitting an embed that is over 2048 characters

So I am trying to make a mod log command for my bot, but once the first log gets over 2048 characters I get this error

UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.description: Must be 2048 or fewer in length.

How can I make it so that when it does reach this limit, it will make a new embed?

Here is my code btw

const moment = require('moment')
const Time = moment().format('MMMM DD YYYY   h:mm:ss a');
const warnModel = require('../../models/ModSchema');



module.exports = {
    name: "logs",
    category: "moderation",
    usage: "logs <UserID>",
    description: "Get the previous moderation logs for a user.",
    execute: async(client, message, member, args) =>  {

      var GetTime = new Date()
      var CurrentTime = Time + " " + GetTime.getHours() + ":" + GetTime.getMinutes() + ":" + GetTime.getSeconds()

      const mentionedMember = message.mentions.members.first() || message.guild.members.cache.get(args[0])

      const warnDoc = await warnModel.findOne({
        guildID: message.guild.id,
        memberID: mentionedMember.id,
      }).catch(err => console.log(err))

      if (!warnDoc || !warnDoc.Warnings.length) {
        return message.channel.send(new MessageEmbed()
            .setDescription(`**?** No warnings were found for ${mentionedMember}`)
            .setTimestamp(message.createdAt)
            .setColor('e30505'))
  }
  const data = []

   let i = 0; warnDoc.Warnings.length > i; i++
  for (let i = 0; warnDoc.Warnings.length > i; i++) {
      data.push(`**Case ${warnDoc.Case[i]}**`)
      data.push(`**User:** ${mentionedMember.user.tag} (${mentionedMember.id})`)
      data.push(`**Type:** ${warnDoc.Type[i]}`)
      data.push(`**Reason:** ${warnDoc.Warnings[i]}`)
      data.push(`**Moderator:** ${await message.client.users.fetch(warnDoc.Moderator[i]).catch(() => 'Deleted User')}`)
      data.push(`**Date:** ${new Date(warnDoc.Date[i]).toLocaleDateString()} ${new Date(warnDoc.Date[i]).toLocaleTimeString()}
`)
  }

  const embed = {
    description: data.join('
')
  }
  const warnAmount = warnDoc.Warnings.length
      
  message.channel.send(`**${warnAmount} logs were found**`, {embed: embed})




  }
}
question from:https://stackoverflow.com/questions/65854745/splitting-an-embed-that-is-over-2048-characters

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...