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

42
LINES

< > BotCompany Repo | #1030358 // discordBot40 - using JDA 4.0 [backup]

JavaX fragment (include)

ifndef DifferentJDA
lib 1400315 // JDA 4.0 with opus

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

import net.dv8tion.jda.api.*;
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.*;

static JDA discordBot40(VF1<MessageReceivedEvent> onMessage) {
  ret discordBot40(new ListenerAdapter {
    @Override
    public void onMessageReceived(MessageReceivedEvent e) {
      if (e.getAuthor().isBot()) ret with print("  Msg from bot, skipping");
      pcallF(onMessage, e);
    }
  });
}

static JDA discordBot40(ListenerAdapter listener, O... _) ctex {
  print("Making JDABuilder");
  JDABuilder builder = new(AccountType.BOT);
  print("Have JDABuilder");
  S token = stringPar token(_);
  if (empty(token)) {
    File tokenFile = javaxSecretDir("discord-bot-token");
    token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile)));
  }
  builder.setToken(token);
  builder.addEventListeners(listener);
  print("Building JDA with token " + shorten(10, token));
  JDA jda = builder.build();
  print("Got JDA: " + jda);
  //jda.awaitSatus(JDA.Status.CONNECTED);
  jda.awaitReady();
  print("Started 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 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030358
Snippet name: discordBot40 - using JDA 4.0 [backup]
Eternal ID of this version: #1030358/1
Text MD5: 133c73266531ab4dcda831fbbcd59d47
Author: stefan
Category: javax / discord
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-07 00:55:23
Source code size: 1428 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 170 / 190
Referenced in: [show references]