|
@@ -0,0 +1,59 @@
|
|
1
|
+package kr.co.swh.lecture.opensource.project.discode;
|
|
2
|
+
|
|
3
|
+import javax.security.auth.login.LoginException;
|
|
4
|
+
|
|
5
|
+import org.javacord.api.DiscordApi;
|
|
6
|
+import org.javacord.api.DiscordApiBuilder;
|
|
7
|
+import org.javacord.api.entity.message.Message;
|
|
8
|
+import org.javacord.api.entity.message.MessageBuilder;
|
|
9
|
+import org.javacord.api.entity.message.component.ActionRow;
|
|
10
|
+import org.javacord.api.entity.message.component.Button;
|
|
11
|
+import org.javacord.api.interaction.MessageComponentInteraction;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+public class JavaCordBot {
|
|
15
|
+
|
|
16
|
+ public static void main(String[] args) throws LoginException, InterruptedException {
|
|
17
|
+ // TODO Auto-generated method stub
|
|
18
|
+ String token = "NjYzMjgzODYxMTUyNTk1OTkz.XhGROw.Ps3JJIKlEXoE1eah_5OKHwViThY";
|
|
19
|
+ DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
|
20
|
+
|
|
21
|
+ // Add a listener which answers with "Pong!" if someone writes "!ping"
|
|
22
|
+ api.addMessageCreateListener(event -> {
|
|
23
|
+ if (event.getMessageContent().equalsIgnoreCase("!ping")) {
|
|
24
|
+
|
|
25
|
+ new MessageBuilder()
|
|
26
|
+ .setContent("Click on one of these Buttons!")
|
|
27
|
+ .addComponents(
|
|
28
|
+ ActionRow.of(Button.success("success", "Send a message"),
|
|
29
|
+ Button.danger("danger", "Delete this message"),
|
|
30
|
+ Button.secondary("secondary", "Remind me after 5 minutes")))
|
|
31
|
+ .send(event.getChannel());
|
|
32
|
+ }
|
|
33
|
+ });
|
|
34
|
+
|
|
35
|
+ api.addMessageComponentCreateListener(event -> {
|
|
36
|
+ MessageComponentInteraction messageComponentInteraction = event.getMessageComponentInteraction();
|
|
37
|
+ String customId = messageComponentInteraction.getCustomId();
|
|
38
|
+
|
|
39
|
+ switch (customId) {
|
|
40
|
+ case "success":
|
|
41
|
+ messageComponentInteraction.createImmediateResponder()
|
|
42
|
+ .setContent("You clicked a button!")
|
|
43
|
+ .respond();
|
|
44
|
+ break;
|
|
45
|
+ case "danger":
|
|
46
|
+ messageComponentInteraction.getMessage().ifPresent(Message::delete);
|
|
47
|
+ break;
|
|
48
|
+ case "secondary":
|
|
49
|
+ messageComponentInteraction.respondLater().thenAccept(interactionOriginalResponseUpdater -> {
|
|
50
|
+ //Code to respond after 5 minutes
|
|
51
|
+ });
|
|
52
|
+ break;
|
|
53
|
+ }
|
|
54
|
+ });
|
|
55
|
+
|
|
56
|
+ // Print the invite url of your bot
|
|
57
|
+ System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
|
|
58
|
+ }
|
|
59
|
+}
|