joeldaniel

JDA Hello World

Nov 9th, 2022 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | Source Code | 0 0
  1. public class Main {
  2.     public static void main(String[] args) throws LoginException, InterruptedException {
  3.  
  4.         // Bot token
  5.         final String token = "DISCORD_TOKEN";
  6.  
  7.         JDA jda = JDABuilder.createDefault(token)
  8.                 .setStatus(OnlineStatus.ONLINE)
  9.  
  10.                 // Event Listeners
  11.                 .addEventListeners(
  12.                         new HelloWorld()
  13.                 )
  14.  
  15.                 .enableCache(CacheFlag.VOICE_STATE)
  16.                 .enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)
  17.                 .setMemberCachePolicy(MemberCachePolicy.ALL)
  18.  
  19.                 .build()
  20.                 .awaitReady();
  21.     }
  22. }
  23.  
  24. // Triggers for EVERY message sent
  25. public class HelloWorld extends ListenerAdapter {
  26.  
  27.     @Override
  28.     public void onMessageReceived(@NotNull MessageReceivedEvent event) {
  29.         event.getMessage().reply("Hello, world!").queue();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment