Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1034048 // shardedDiscordBot40 - using JDA 4.x

JavaX fragment (include) [tags: use-pretranspiled]

Uses 10105K of libraries. Click here for Pure Java version (4953L/28K).

1  
ifndef DifferentJDA
2  
//lib 1400315 // JDA 4.0 with opus
3  
lib 1400445 // JDA 4.2 with opus
4  
5  
//static LS _stickyLibs_discordBot = ll(#1400315); // can cause loader constraint violations
6  
endifndef
7  
8  
import net.dv8tion.jda.api.*;
9  
import net.dv8tion.jda.api.sharding.*;
10  
import net.dv8tion.jda.api.entities.*;
11  
import net.dv8tion.jda.api.entities.Member;
12  
import net.dv8tion.jda.api.hooks.*;
13  
import net.dv8tion.jda.api.events.message.*;
14  
import net.dv8tion.jda.api.events.message.react.*;
15  
import static net.dv8tion.jda.api.requests.GatewayIntent.*;
16  
17  
static ShardManager shardedDiscordBot40(ListenerAdapter listener, O... _) ctex {
18  
  S token = stringPar token(_);
19  
  if (empty(token)) {
20  
    File tokenFile = javaxSecretDir("discord-bot-token");
21  
    token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)));
22  
  }
23  
  print("Making DefaultShardManagerBuilder");
24  
  DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(token,
25  
    GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES);
26  
  print("Have DefaultShardManagerBuilder");
27  
  if (boolPar membersIntent(_))
28  
    builder.enableIntents(GUILD_MEMBERS);
29  
  builder.addEventListeners(listener);
30  
  print("Building JDA with token " + shorten(10, token));
31  
  ShardManager jda = builder.build();
32  
  print("Got JDA: " + jda);
33  
  //jda.awaitSatus(JDA.Status.CONNECTED);
34  
  //jda.awaitReady();
35  
  //print("Started sharded Discord bot (token: " + shorten(token, 7) + ")");
36  
  ret jda;
37  
}

Author comment

Began life as a copy of #1026291

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034048
Snippet name: shardedDiscordBot40 - using JDA 4.x
Eternal ID of this version: #1034048/4
Text MD5: dc50a62a304db156d530f813f5123263
Transpilation MD5: 574072de2ad6facfdd96514ac2fde95f
Author: stefan
Category: javax / discord
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-19 15:54:04
Source code size: 1493 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 114 / 173
Version history: 3 change(s)
Referenced in: [show references]