skip to Main Content

I’m trying to create a Pokemon-type command where you catch friends on Discord. I was able to get it to create the information for catching different users to Mongo DB, but it creates separate queries for each new user caught. I’m having issues creating an embed that shows a box for the user that shows each of the users caught and how many times they have.

I’ve tried a few different ways using collections and other methods, but nothing has worked.

Catch command(not the full command since it’s over 1000 lines of code):
// Check if the Forgemon exists in the database. let nameBox = await fmBoxSchema.findOne({ User: user, Username: user.username, Guild: interaction.guild.id, name: fmTarget.forgemon, });

// Forgemon is not caught yet, add it to the data
   if (!nameBox) {                  
                  nameBox = new fmBoxSchema({
                    User: user,
                    Username: user.username,
                    Guild: interaction.guild.id,
                    name: fmTarget.forgemon,
                    caught: 0,
                  });
                  await nameBox.save();

                  // Set the Forgemon's "caught" count.
                  nameBox.caught = 1;
                  await nameBox.save();

If more code is needed I can always paste the whole thing in a paste bin and share it, but this is what I use and have that works with adding the information to Mongo DB.

Below is what I currently have for trying to show the user who all they’ve caught and how many times, but keep getting and error saying "Cannot send an empty message". Full error at bottom.

// Get the user's Pokémon from the database.
        const userForgemon = await fmBoxSchema.findOne({ User });

        // Create a message that lists the user's Pokémon.
        let message = "```";
        if (userForgemon) {
          for (const [name, caught] of Object.entries(
            userForgemon
          )) {
            message += `${name} - Caught ${caught} timesn`;
          }
        } else {
          message = "You have not caught any Pokémon yet.";
        }
        message += "```";

        // Send the message to the user.
        let userPFP = user.displayAvatarURL();

        boxEmbed = new EmbedBuilder()
        .setTitle(`${user.username}'s Box.`)
        .setThumbnail(userPFP)
        .setDescription(message)

        interaction.reply({ embed: boxEmbed })

Error:

throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
            ^

DiscordAPIError[50006]: Cannot send an empty message
    at handleErrors (D:BotsTestBot - [email protected]:640:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async BurstHandler.runRequest (D:BotsTestBot - [email protected]:736:23)
    at async REST.request (D:BotsTestBot - [email protected]:1387:22)
    at async ChatInputCommandInteraction.reply (D:BotsTestBot - V14node_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:111:5) {
  requestBody: {
    files: [],
    json: {
      type: 4,
      data: {
        content: undefined,
        tts: false,
        nonce: undefined,
        embeds: undefined,
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: undefined,
        message_reference: undefined,
        attachments: undefined,
        sticker_ids: undefined,
        thread_name: undefined
      }
    }
  },
  rawError: { message: 'Cannot send an empty message', code: 50006 },
  code: 50006,
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/interactions/1115070713695567924/aW50ZXJhY3Rpb246MTExNTA3MDcxMzY5NTU2NzkyNDpjbHN0d2ZzTGcxRXJUMUdKMEE0WWdZRDdtR3NJTnhWN1hMSnBxblpkV3Y0bFplWUZibnBoOXhPdlVkU2ZqNVY4VGpRb0lCaUJscVVhWnZ3TmhuSHdvZlhVOWx5S2ZlN2tqa0UzNkYyUlZkTVdVYkk1c2VSS3E4MmJUVDZDVXhYNw/callback'
}

2

Answers


  1. Chosen as BEST ANSWER

    The answer to the main questions was my type of embeds and then the error after that needed me to change boxEmbed to [boxEmbed] for the array.


  2. In line with interaction.reply({ embed: boxEmbed })

    Replace

    embed: boxEmbed
    

    With

    embeds: boxEmbed
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search