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).

ifndef DifferentJDA
//lib 1400315 // JDA 4.0 with opus
lib 1400445 // JDA 4.2 with opus

//static LS _stickyLibs_discordBot = ll(#1400315); // can cause loader constraint violations
endifndef

import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.sharding.*;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.hooks.*;
import net.dv8tion.jda.api.events.message.*;
import net.dv8tion.jda.api.events.message.react.*;
import static net.dv8tion.jda.api.requests.GatewayIntent.*;

static ShardManager shardedDiscordBot40(ListenerAdapter listener, O... _) ctex {
  S token = stringPar token(_);
  if (empty(token)) {
    File tokenFile = javaxSecretDir("discord-bot-token");
    token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)));
  }
  print("Making DefaultShardManagerBuilder");
  DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(token,
    GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES);
  print("Have DefaultShardManagerBuilder");
  if (boolPar membersIntent(_))
    builder.enableIntents(GUILD_MEMBERS);
  builder.addEventListeners(listener);
  print("Building JDA with token " + shorten(10, token));
  ShardManager jda = builder.build();
  print("Got JDA: " + jda);
  //jda.awaitSatus(JDA.Status.CONNECTED);
  //jda.awaitReady();
  //print("Started sharded Discord bot (token: " + shorten(token, 7) + ")");
  ret jda;
}

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: 113 / 171
Version history: 3 change(s)
Referenced in: [show references]