yourWaifu / sleepy-discord

C++ library for the Discord chat client. Please use Rust for new bots
https://yourWaifu.github.io/sleepy-discord/
MIT License
708 stars 93 forks source link

Can't edit messages to remove all components. #232

Open MacDue opened 3 years ago

MacDue commented 3 years ago

It does not seem like it's currently possible to remove all buttons from a message when handling an interaction with createInteractionResponse().

To remove all buttons/components you must set the components field to an empty array, however, if you do this it appears that the JSON serializer ignores the component field (not adding it or the empty array in the update) -- making it impossible to remove buttons.

The root issue seems to be treating an empty vector as representing not present, it probably should be something like std::optional<std::vector<Components>> to separate the "not present" and "empty" states.

MacDue commented 3 years ago

The minimal fix for my bot was to add json::OPTIONAL_NON_EMPTY_FIELD which means the the "components" field is always sent. This is not a true fix though since it means you can't ever not edit the components now (which is fine for me currently).

yourWaifu commented 3 years ago

I wonder what a vector with one nullptr does. I might make that represent the empty array value.

MacDue commented 3 years ago

I wonder what a vector with one nullptr does. I might make that represent the empty array value.

I tried a vector with an empty action bar and that was an invalid request, I'm not sure if [null] would be but I would guess it might be.

Edit: I see what you mean, that'd probably work for this case if handled to just produce an empty array in the serializer.

MacDue commented 3 years ago

This issue extends to more than just components. You can't edit a message to remove the "content" if you want to edit a message to contain just an embed (in an interaction -- but I assume it holds for the normal edit message)