Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
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}`)
  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})


Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share