DiaDuck
DiaDuck

Reputation: 9

Discord bot unable to send messages in java using JDA

My discord bot does all the neccaserry things so that on paper it should work but it doesnt

when ran the console/terminal prints as follows:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J:
See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details. SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation. SLF4J:
See http://www.slf4j.org/codes.html#no_static_mdc_binder for further
details. [main] INFO JDA - Login Successful! [JDA MainWS-WriteThread]
INFO WebSocketClient - Connected to WebSocket [JDA MainWS-ReadThread]
INFO JDA - Finished Loading!

Class Main.java below:

import net.dv8tion.jda.api.JDABuilder;

public class Main {
    public static void main(String[] args) throws Exception{
        try {
            net.dv8tion.jda.api.JDA api = JDABuilder.createDefault("********************").build();
            api.addEventListener(new MyEventListener());
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }
}

Class MyEventListener.java below:

import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class MyEventListener extends ListenerAdapter {
    public void onMessageReceived(MessageReceivedEvent event) {
        if (event.getAuthor().isBot()) return;
        
        Message message = event.getMessage();
        String content = message.getContentRaw();
        MessageChannel channel = event.getChannel();
        
        if (content.startsWith("?test")) {
            channel.sendMessage(":thinking:");
        }
    }

}

when i put createDefault("********************").build(); the *********** is the bots token, it is correct

Upvotes: 0

Views: 357

Answers (1)

MrBorder
MrBorder

Reputation: 369

You didn't call the queue() on channel.sendMessage(":thinking:"); which returns a MessageAction (An implementation of RestAction<Message>. For more info see links below.

More details:

Nothing happens when using x

RestAction in JDA

Upvotes: 2

Related Questions