'Discord Bot unable to send messages

I'm developing a discord bot, but I'm having some problems that I've never had. My discord bot is unable to send messages. The bot doesn't contain any deprecated methods. Here is the code:

Main:

private Main() throws LoginException {
    final JDA jda = JDABuilder.createDefault("My.Token.Here", GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_VOICE_STATES).build();

    CommandClientBuilder builder = new CommandClientBuilder();
    builder.setOwnerId("778564522046128148");
    builder.setActivity(Activity.watching("es bueda fixe!"));

    CommandClient client = builder.build();

    jda.addEventListener(client);
    jda.addEventListener(new JoinLeave());
    jda.addEventListener(new TestCommand());
}

public static void main(String[] args) throws LoginException{
    long enable = System.currentTimeMillis();
    new Main();
    System.out.println("Bot enabled in: " + (System.currentTimeMillis() - enable) + "ms!");
}

TestCommand (to test if the bot works):

public class TestCommand extends ListenerAdapter {

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent e){
    System.out.println("hefdfs");
    if(e.getMessage().getContentRaw().equalsIgnoreCase("!test")){
        e.getChannel().sendMessage("test").queue();
    }
}

}

Thanks.



Solution 1:[1]

You disabled the GUILD_MESSAGES intent. Add it to your list of intents when calling createDefault:

EnumSet<GatewayIntent> intents = EnumSet.of(
  GatewayIntent.GUILD_MEMBERS, // for member join/remove events and cache
  GatewayIntent.GUILD_EMOJIS, // for Guild#getEmotes (not very useful)
  GatewayIntent.GUILD_VOICE_STATES, // for member voice states
  GatewayIntent.GUILD_MESSAGES // for message received event
);
JDA jda = JDABuilder.createDefault("My.Token.Here", intents)
                    .addEventListeners(new TestCommand(), new JoinCommand(), client)
                    .build();

Read up Gateway Intents and Member Caching

Solution 2:[2]

You forget to add GatewayIntent.GUILD_MESSAGES, you should add it

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Minn
Solution 2 omar ibrahim