Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Incorrectly structured request causes create_guild_ban to fail #48

Closed
jpahm opened this issue Jul 26, 2020 · 2 comments
Closed

Incorrectly structured request causes create_guild_ban to fail #48

jpahm opened this issue Jul 26, 2020 · 2 comments

Comments

@jpahm
Copy link
Contributor

jpahm commented Jul 26, 2020

The code in guild.cpp for create_guild_ban incorrectly PUTs the reason and delete_message_days parameters to Discord as URL parameters. This causes an HTTP 400 Bad Request response, as the Discord docs specify that that these parameters should be sent as a JSON object, seen here.

I noticed this issue when the ban command for my bot failed, and resolved the issue by changing the code for the create_guild_ban method to the following:

AEGIS_DECL aegis::future<rest::rest_reply> guild::create_guild_ban(snowflake user_id, int8_t delete_message_days, const std::string & reason)
{
#if !defined(AEGIS_DISABLE_ALL_CACHE)
    if (!perms().can_ban())
        return aegis::make_exception_future(error::no_permission);
#endif

    std::shared_lock<shared_mutex> l(_m);

    json obj = { { "delete_message_days", delete_message_days }, { "reason", reason } };

    return _bot->get_ratelimit().post_task({ fmt::format("/guilds/{}/bans/{}", guild_id, user_id), rest::Put, obj.dump()});
}
@zeroxs
Copy link
Owner

zeroxs commented Jul 26, 2020

Odd. It used to be done via query params. It looks like it was changed. I was not aware of this change. If you'd like to make a PR for that change I can merge it in.

@jpahm
Copy link
Contributor Author

jpahm commented Jul 26, 2020

Will do, thanks for the speedy response.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants