1 | ifndef DifferentJDA |
2 | lib 1400315 // JDA 4.0 with opus |
3 | |
4 | //static LS _stickyLibs_discordBot = ll(#1400315); // can cause loader constraint violations |
5 | endifndef |
6 | |
7 | import net.dv8tion.jda.api.*; |
8 | import net.dv8tion.jda.api.entities.*; |
9 | import net.dv8tion.jda.api.entities.Member; |
10 | import net.dv8tion.jda.api.hooks.*; |
11 | import net.dv8tion.jda.api.events.message.*; |
12 | import net.dv8tion.jda.api.events.message.react.*; |
13 | |
14 | static JDA discordBot40(VF1<MessageReceivedEvent> onMessage) { |
15 | ret discordBot40(new ListenerAdapter { |
16 | @Override |
17 | public void onMessageReceived(MessageReceivedEvent e) { |
18 | if (e.getAuthor().isBot()) ret with print(" Msg from bot, skipping"); |
19 | pcallF(onMessage, e); |
20 | } |
21 | }); |
22 | } |
23 | |
24 | static JDA discordBot40(ListenerAdapter listener, O... _) ctex { |
25 | print("Making JDABuilder"); |
26 | JDABuilder builder = new(AccountType.BOT); |
27 | print("Have JDABuilder"); |
28 | S token = stringPar token(_); |
29 | if (empty(token)) { |
30 | File tokenFile = javaxSecretDir("discord-bot-token"); |
31 | token = assertNempty("Need: " + tokenFile, trim(loadTextFile(tokenFile))); |
32 | } |
33 | builder.setToken(token); |
34 | builder.addEventListeners(listener); |
35 | print("Building JDA with token " + shorten(10, token)); |
36 | JDA jda = builder.build(); |
37 | print("Got JDA: " + jda); |
38 | //jda.awaitSatus(JDA.Status.CONNECTED); |
39 | jda.awaitReady(); |
40 | print("Started Discord bot (token: " + shorten(token, 7) + ")"); |
41 | ret jda; |
42 | } |
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: | 171 / 191 |
Referenced in: | [show references] |