Cogmasters/concord

`discord_bulk_overwrite_global_application_command` doesn't work with partial commands

invakid404 opened this issue · 8 comments

Describe the bug
Calling discord_bulk_overwrite_global_application_command with partial application command data results in an API error, stating that "the command has an invalid ID".

Expected behavior
Bulk overwriting of commands should work with partial application command data.

To Reproduce
Any call to discord_bulk_overwrite_global_application_command with application commands with no IDs should trigger the bug.

Version
aa57b19 (master)

Stack trace
N/A

Additional context
I briefly looked at the issue with a debugger, looks like the issue is that the library serializes the ID of the partial commands (which is 0), which results in the Discord API erroring out. The correct behavior would be to omit the ID from the body.

Thanks for notifying us - are you able to replicate this bug from the dev branch?

@lcsmuller indeed. I can tell the function name was renamed (an 's' was appended), but it still takes a discord_application_commands struct, so I'm assuming it's still putting "id":0 for all of the commands in the request body.

Here's the actual Discord API response btw:

02:59:05 ERROR discord-rest_request.c:382: [DISCORD_REQUEST] {"code": 50035, "errors": {"0": {"_errors": [{"code": "APPLICATION_COMMANDS_INVALID_ID", "message": "Invalid application command id provided"}]}}, "message": "Invalid Form Body"}

Please give latest dev a try, if you're doing a git pull make sure to run make purge first so gencodecs files are generated from scratch.

Latest dev works like a charm, thanks @lcsmuller!

BTW, since I'm not familiar with your release schedule, when can I expect a new release to come out for the fix?

BTW, since I'm not familiar with your release schedule, when can I expect a new release to come out for the fix?

Hopefully soon but we still got a couple things that needs to be tackled first. You can keep track of #74 to know when the next release has been merged, or join our Discord server to get notified.

Cool, I'll just use the dev branch for now.

I'm using dev version of library and this still doesn't work.

Reproduction:

  1. Library installation
git clone https://github.com/Cogmasters/concord
cd concord
git checkout dev
make
sudo make install
  1. Code
#include <concord/discord.h>
#include <string.h>

void on_ready(struct discord *client, const struct discord_ready *event) {
  struct discord_create_global_application_command params = {
      .name = "example", .description = "example description"};
  discord_bulk_overwrite_global_application_commands(
      client, event->application->id, &params, NULL);
}

void on_interaction(struct discord *client,
                    const struct discord_interaction *event) {
  if (event->type != DISCORD_INTERACTION_APPLICATION_COMMAND)
    return; /* return if interaction isn't a slash command */

  if (strcmp(event->data->name, "example") == 0) {
    struct discord_interaction_response params = {
        .type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE,
        .data = &(struct discord_interaction_callback_data){.content = "pong"}};
    discord_create_interaction_response(client, event->id, event->token,
                                        &params, NULL);
  }
}

int main() {
  struct discord *client = discord_init("PASTE YOUR TOKEN HERE!");
  discord_set_on_ready(client, &on_ready);
  discord_set_on_interaction_create(client, &on_interaction);
  discord_run(client);
  return 0;
}
  1. Compilation command
    clang main.c -o main -g -ldiscord -lcurl

image
image