Why my Discord bot only responds to direct messages but not in servers? (Java, Javacord, Spring Boot)

Viewed 19

Here is my code. I have granted the bot Adminastor permissions, and I still manually granted all permissions for the bot. I tried making a test server, but the bot still does not respond in servers; it only responds to direct messages.

import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

@SpringBootApplication
public class GramophoneApplication {

    @Autowired
    private Environment env;

    public static void main(String[] args) {
        SpringApplication.run(GramophoneApplication.class, args);


    }

    @Bean
    @ConfigurationProperties(value = "token")
    public DiscordApi discordApi(){
        String token = env.getProperty("token");
        DiscordApi api = new DiscordApiBuilder().setToken(token)
                .setAllNonPrivilegedIntents()
                .login()
                .join();

        api.addMessageCreateListener(event -> {
            if(event.getMessageContent().equals("!ping")){
                event.getChannel().sendMessage("Pong!");
            }
        });
        return api;
    }

}
0 Answers
Related