Json parse error after editing a message in a thread when that edit invited members
See original GitHub issueBug Report
When editing a message in a thread in a way that doing so will join other members to the thread by mentioning them (tested with a role with multiple members in my test case), a Json-parse error will occur, logging the exception and sometimes (but oddly not always) preventing the success consumer of the queue
method to execute, even though the message is correctly edited.
Expected Behavior
After the message being edited the callback would always be executed normally and no errors would be thrown.
Code Example or Reproduction Steps
Edit a message in a thread in a way that joins other members.
My use-case is adding moderators to newly created threads without directly pinging them, and removing the mentions after that.
The code I use is the following, inside a ListenerAdapter
:
public void onChannelCreate(ChannelCreateEvent event) {
if (event.isFromType(ChannelType.GUILD_PUBLIC_THREAD)) {
ThreadChannel thread = (ThreadChannel) event.getChannel();
Member owner = thread.getOwner();
if (!owner.getUser().equals(event.getJDA().getSelfUser())) {
JDA jda = event.getJDA();
final String topMessage = "Welcome to your new thread, " + owner.getAsMention() + "!";
final String modsPing = jda.getRoleById(Constants.MODERATOR_ROLE).getAsMention() + " and " +
jda.getRoleById(Constants.TRIAL_MODERATOR_ROLE).getAsMention();
thread.sendMessage(topMessage)
.queue(message -> message.editMessage(topMessage + " Joining " + modsPing + "...")
.queue(msg -> msg.editMessage(topMessage).queue()));
}
}
}
The callback after the message that adds "Joining" + modsPing
isn’t always executed, therefore the mentions are kept in the message.
Code for JDABuilder or DefaultShardManagerBuilder Used
JDABuilder.createDefault(Constants.TOKEN)
.setEnabledIntents(
GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_BANS,
GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_WEBHOOKS,
GatewayIntent.GUILD_INVITES, GatewayIntent.GUILD_VOICE_STATES,
GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_MESSAGES,
GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_MESSAGE_TYPING,
GatewayIntent.DIRECT_MESSAGES, GatewayIntent.DIRECT_MESSAGE_TYPING,
GatewayIntent.DIRECT_MESSAGE_REACTIONS
)
.setRawEventsEnabled(true)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.setChunkingFilter(ChunkingFilter.ALL)
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setActivity(Activity.watching("Loading..."))
.setAutoReconnect(true)
.addEventListeners(new ThreadAdder())
.build();
Exception or Error
Got an unexpected Json-parse error. Please redirect the following message to the devs:
JDA 5.0.0-alpha.2_ae1fabf
Unable to resolve value with key presence to type DataObject: null
THREAD_MEMBERS_UPDATE -> {"guild_id":"893172681367777281","added_members":[**array of members**],"id":"920015298906685520","member_count":11}
net.dv8tion.jda.api.exceptions.ParsingException: Unable to resolve value with key presence to type DataObject: null
at net.dv8tion.jda.api.utils.data.DataObject.valueError(DataObject.java:807)
at net.dv8tion.jda.api.utils.data.DataObject.lambda$getObject$0(DataObject.java:277)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at net.dv8tion.jda.api.utils.data.DataObject.getObject(DataObject.java:277)
at net.dv8tion.jda.internal.entities.EntityBuilder.createThreadMember(EntityBuilder.java:1196)
at net.dv8tion.jda.internal.handle.ThreadMembersUpdateHandler.handleAddedThreadMembers(ThreadMembersUpdateHandler.java:88)
at net.dv8tion.jda.internal.handle.ThreadMembersUpdateHandler.handleInternally(ThreadMembersUpdateHandler.java:64)
at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:953)
at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:840)
at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:818)
at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:992)
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)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Gotcha. I’ve enquired with Discord Devs about whether or not we could get the added ability to be able to add members via role. Something like
ThreadChannel#addMembersFromRole(Role)
perhaps.Well the bot previously didn’t have the feature, so yeah it’s added just for easily adding the entire role, though I’m also thinking on getting it pinned as an easy way to find the top of the thread, so it has more purpose.