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.

MessageRecievedEvent running 2 times

See original GitHub issue

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest JDA version
  • I have checked the branches or the maintainers’ PRs for upcoming bug fixes.

Expected Behaviour

Should delete a message if the bot sends it, and send one message whenever a user sends a message.

Code Example for Reproduction Steps

if (AUTHOR.isBot()) return;

            MessageCreateAction action = event.getChannel().asTextChannel().sendMessage(AUTHOR.getAsTag() + " SENT A MESSAGE IN " + event.getGuild().getName() + pingst);
            Message msg = action.complete();
            msg.delete().queue();


MY ENTIRE DMPing.java class: https://pastebin.com/96uxUzbG

Code for JDABuilder or DefaultShardManagerBuilder used

builder = DefaultShardManagerBuilder.createLight(TOKEN);

// Set Custom Status
builder.setStatus(OnlineStatus.ONLINE); builder.setActivity(Activity.listening("To your DMs"));

// Build the Bot
builder.setMemberCachePolicy(MemberCachePolicy.ALL);
builder.setChunkingFilter(ChunkingFilter.ALL);
builder.enableIntents(GatewayIntent.getIntents(GatewayIntent.ALL_INTENTS));
shardManager = builder.build();

// Register Listeners
shardManager.addEventListener(new dmPing());
shardManager.addEventListener(new CommandManager());

Exception or Error

There is no error, it just runs 2 times for some reason.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Feniksovichcommented, Oct 31, 2022

So you saw the print twice, if you print outside of the queue, is it showing twice also ?

If so, you may have registered your listener twice.

Oh, really sorry, my bad. My database callback calls two times then the message sends two times. I’ve been looking for the root of the problem in literally everything and came here hoping to see something looks like my issue.

0reactions
MinnDevelopmentcommented, Nov 5, 2022

Closing this due to inactivity. Generally, I would recommend registering the event listener on the builder instead of after building.

Read more comments on GitHub >

github_iconTop Results From Across the Web

window message Event firing more than one time sometime
But the message event fires in the parent page more than one times. If it fires more than one time the counter will...
Read more >
Same event is received multiple times
I am using this code to receive NewEventIndication: MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.
Read more >
Message received twice when rocket chat server restarts #141
It does not send the message twice (if it is a command that triggers something), but it is received twice.
Read more >
Web worker on message gets called twice : r/learnjavascript
This log message was printed only once. I conclude that the postMessage is indeed run only once, but it goes into some event...
Read more >
Javascript Event Handler is firing twice - Elixir Forum
Have you checked if you run the code more than once? Maybe you have added two event listeners. yreuvekamp ...
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