discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.22k stars 727 forks source link

Support SelectMenu in Modal #2161

Open fuma-nama opened 2 years ago

fuma-nama commented 2 years ago

General Troubleshooting

Expected Behaviour

TextInput and Modal are added in alpha 11, now Discord API also allows SelectMenu to be used in Modal. However, JDA failed to parse data when SelectMenu is used in Modal.

The exception is throwed outside the onModalInteraction(ModalInteractionEvent event) method

Exception or Error

[JDA MainWS-ReadThread] WARN WebSocketClient - Got an unexpected Json-parse error. Please redirect the following message to the devs:
    JDA 5.0.0-alpha.12_edbc423
    Unable to resolve value with key value to type String: null
    INTERACTION_CREATE -> {"data":{"components":[{"components":[{"values":["fdws"],"custom_id":"select_todo","type":3}],"type":1}],"custom_id":"1"},"id":"989386933446791179","type":5,"message":{"mention_everyone":false,"pinned":false,"components":[{"components":[{"custom_id":"2","style":1,"label":"Add","type":2},{"custom_id":"3","style":1,"label":"Delete","type":2}],"type":1}],"attachments":[],"author":{"bot":true,"public_flags":0,"id":"907955781972918283","avatar":"d9f145676d8483f0fcb43f25bf0dab0e","username":"BadDog","discriminator":"1660","avatar_decoration":null},"flags":0,"type":20,"mention_roles":[],"application_id":"907955781972918283","edited_timestamp":"2022-06-23T04:30:20.188000+00:00","content":"**TODO List**\n\nfdws\n","tts":false,"webhook_id":"907955781972918283","mentions":[],"interaction":{"name":"todo","id":"989386873183035392","type":2,"user":{"public_flags":256,"id":"572329183334891520","avatar":"278effc51d638314c09e0d611e7be0e3","username":"MONEY","discriminator":"3897","avatar_decoration":null}},"id":"989386874651033600","embeds":[],"channel_id":"959407174591873045","timestamp":"2022-06-23T04:30:12.836000+00:00"},"locale":"en-US","version":1,"user":{"public_flags":256,"id":"572329183334891520","avatar":"278effc51d638314c09e0d611e7be0e3","username":"MONEY","discriminator":"3897","avatar_decoration":null},"channel_id":"959407174591873045","application_id":"907955781972918283","token":"aW50ZXJhY3Rpb246OTg5Mzg2OTMzNDQ2NzkxMTc5OkN6YTN1Zjl1elZpTFJqWHlGU2NNZ0lWdExrcENtbnFtUWQ0U0VWaW8wMXJqY2I1bGNuOFdCNlpwUWlRSFExZkhFbm1ibEdUZE0wSURIZGtkRGRNWW5Cb0NNQUhlcERQVFhkS254Tk5BWjhlU2t6MVdZSWRwb2t0QnlsdmhTbnZI"}
net.dv8tion.jda.api.exceptions.ParsingException: Unable to resolve value with key value to type String: null
    at net.dv8tion.jda.api.utils.data.DataObject.valueError(DataObject.java:807)
    at net.dv8tion.jda.api.utils.data.DataObject.getString(DataObject.java:403)
    at net.dv8tion.jda.api.interactions.modals.ModalMapping.<init>(ModalMapping.java:41)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.stream.IntPipeline$1$1.accept(IntPipeline.java:180)
    at java.base/java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:104)
    at java.base/java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:699)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
    at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.IntPipeline$1$1.accept(IntPipeline.java:180)
    at java.base/java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:104)
    at java.base/java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:699)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at net.dv8tion.jda.internal.interactions.ModalInteractionImpl.<init>(ModalInteractionImpl.java:50)
    at net.dv8tion.jda.internal.handle.InteractionCreateHandler.handleInternally(InteractionCreateHandler.java:91)
    at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:957)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:844)
    at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:822)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:996)
    at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
    at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
    at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
    at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
    at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
    at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
    at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
Xirado commented 2 years ago

Did you manage to send a Modal that contains a SelectMenu with JDA? Putting them in Modals is not yet officially released nor documented.

Tais993 commented 2 years ago

Select menus aren't officially supported by Discord, once it's documentation is published JDA will implement it

Kascald commented 1 week ago

Are you still experiencing the issue? I wanted to add a StringSelectMenu to a Modal in the same way, but according to the official documentation (https://jda.wiki/using-jda/interactions/#modals), ''Similarly to messages, Modals can contain up to 5 ActionRows, although the only component that can be put inside Modals at the moment (TextInput) takes up a whole ActionRow.'' This means that only TextInput can be added to modals.

Therefore, I solved this by modifying the process to reply to the interaction with event.reply().addActionRow() upon submitting the modal through onModalInteraction. I added a Button to addActionRow() and used the button interaction to generate a StringSelectMenu. Additionally, if multiple threads access and modify objects during the process, you might want to add measures to handle this.

MCausc78 commented 1 week ago

Are you still experiencing the issue? I wanted to add a StringSelectMenu to a Modal in the same way, but according to the official documentation (https://jda.wiki/using-jda/interactions/#modals), ''Similarly to messages, Modals can contain up to 5 ActionRows, although the only component that can be put inside Modals at the moment (TextInput) takes up a whole ActionRow.'' This means that only TextInput can be added to modals.

Therefore, I solved this by modifying the process to reply to the interaction with event.reply().addActionRow() upon submitting the modal through onModalInteraction. I added a Button to addActionRow() and used the button interaction to generate a StringSelectMenu. Additionally, if multiple threads access and modify objects during the process, you might want to add measures to handle this.

Modals can have only TextInput's. This issue and related PR exist because discord enabled selects in modals by accident