Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responding to interaction with public message update implicitly clears components, embeds & files #701

Open
Ampflower opened this issue Oct 16, 2022 · 1 comment

Comments

@Ampflower
Copy link

Ampflower commented Oct 16, 2022

Description

Within UpdateMessageInteractionResponseCreateBuilder, there's non-nullable fields named components, embeds and files, each populated with an empty list.

override var files: MutableList<NamedFile> = mutableListOf()
override var content: String? = null
override var tts: Boolean? = null
override var embeds: MutableList<EmbedBuilder> = mutableListOf()
override var allowedMentions: AllowedMentionsBuilder? = null
override var components: MutableList<MessageComponentBuilder> = mutableListOf()

This empty list makes it impossible to persist components, embeds and files without having to redefine them.

This is also inconsistent with the regular MessageBehavior.edit {} API, and inconsistent with JDA, both of which can persist components, embeds and files without having to redefine them anywhere in the code.

Steps to reproduce

In this case, it happened with buttons.

kord.on<ButtonInteractionCreateEvent> {
  interaction.updatePublicMessage { content = Math.random().toString() }
}

Expected behaviour

With the given example above, clicking the button would only change the content of the message to a random double, leaving the button and other input intact.

Actual behaviour

The message gets edited to a random double, while also removing the input.

Workarounds

  • Tell the API you're deferring an edit, and edit using the original message behaviour and its API.
  • Manually adding all components that were originally on the message.

Forcefully setting the lists to null (which would've normally cleared this bug entirely) will bug-check due to Optional having an explicit non-nullable API.

Extra

This may affect other aspects of code.
Side effect of fixing this will bring a breaking API change to applications expecting the current behaviour, which is clearing on interaction edit or fixing the list itself.

@Ampflower Ampflower changed the title Responding to interaction with public message update implicitly clears components Responding to interaction with public message update implicitly clears components, embeds & files Oct 16, 2022
@lukellmann
Copy link
Member

Thanks for the detailed report!

I've also come accross this before but didn't get to fixing it yet.

I think it's fine to break applications depending on the current behavior if we have a warning about this in the release that delivers this fix.

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

No branches or pull requests

2 participants