concord icon indicating copy to clipboard operation
concord copied to clipboard

Only first attachment is being detected

Open Furmissile opened this issue 3 years ago • 0 comments

ERROR discord-rest_request.c:382: [DISCORD_REQUEST] {"code": 50035, "errors": {"attachments": {"1": {"_errors": [{"code": "ATTACHMENT_NOT_FOUND", "message": "Attachment data not found"}]}}}, "message": "Invalid Form Body"}

This error only occurs when more than one attachment has been included. Otherwise, using one or the other works. Replacing the strings with proper files should reproduce the error:

struct discord_attachment load_attachment(char* filename) {
  char full_path[128];
  snprintf(full_path, sizeof(full_path), "File/Path/%s", filename);

  size_t fsize = 0;
  char  *fbuf  = cog_load_whole_file(full_path, &fsize);
  struct discord_attachment attachment = {
    .filename = filename, 
    .content = fbuf, 
    .size = fsize
  };

  return attachment;
}

void embed_create(struct discord *client, const struct discord_message *msg) {
  if (msg->author->bot) return;

  struct discord_embed embed = {
    .image = &(struct discord_embed_image) {
      .url = "attachment://file_name.png"
    },
    .thumbnail = &(struct discord_embed_thumbnail) {
      .url = "attachment://file_name.png"
    }
  };

  struct discord_attachment add_image = load_attachment("file_name.png");
  struct discord_attachment add_thumbnail = load_attachment("file_name.png");

  struct discord_create_message params = {
    .embeds = &(struct discord_embeds) {
      .size = 1,
      .array = &embed
    },
    .attachments = &(struct discord_attachments) {
      .size = 2,
      .array = (struct discord_attachment[]) {add_image, add_thumbnail}
    }
  };

  discord_create_message(client, msg->channel_id, &params, NULL);
}

Furmissile avatar Aug 05 '22 01:08 Furmissile