Absurd
Absurd

Reputation: 1

How to fix discord jda bot spam

I'm working on a Discord bot but when I try to send a message to a channel, it doesn't work.

I tried to use the code event.getChannel().sendMessage("Hello!").queue(); But this one spams my discord.

public void onGuildMessageReceived (GuildMessageReceivedEvent event){
    if(event.getChannel().getId().equalsIgnoreCase("607560497083973632")){
        event.getChannel().sendMessage("Hello!").queue();
    }
}

This is what happens: https://prntscr.com/oo6622

Upvotes: 0

Views: 707

Answers (1)

Minn
Minn

Reputation: 6131

You receive your own messages. To prevent this you can just check if the received message is from the current user.

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event){
    if (event.getAuthor().equals(event.getJDA().getSelfUser())) return; // ignore own messages
    if (event.getChannel().getIdLong() == 607560497083973632L){ // use long for ids
        event.getChannel().sendMessage("Hello!").queue();
    }
}

Upvotes: 0

Related Questions