question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Json parse error after editing a message in a thread when that edit invited members

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DV8FromTheWorldcommented, Dec 14, 2021

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.

0reactions
altrisicommented, Dec 14, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Json Parse Error line 22: Json Deserialization; unknown ...
Json Parse Error line 22: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping ... All of that needs to be done before ...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Getting "JSON parse error: Missing a name for object member ...
On run, I am getting the following error: ArgumentException: JSON parse error: Missing a name for object member. UnityEngine.JsonUtility.
Read more >
Error while parsing JSON Response in REST API Post call
I have copied and pasted the REST Request and Response JSON definitions into the Request and Response text boxes provided by OS REST...
Read more >
Mattermost self-hosted changelog
Autocomplete results using Elasticsearch or Bleve will correctly show a user as a channel member in direct message and group message channels. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found