Skip to content

Commit a6c9c5e

Browse files
authored
Create README.md
1 parent 766d2a0 commit a6c9c5e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Java-Discord-Framework
2+
Designed to make developing bots faster and simpler!
3+
4+
## Setting up your main class
5+
In your main class, you need to extend `DiscordBot`, like this:
6+
```java
7+
import javax.security.auth.login.LoginException;
8+
9+
public class BotExample extends DiscordBot {
10+
11+
public BotExample() throws LoginException, InterruptedException {
12+
super("token");
13+
registerCommands(new CommandExample());
14+
build();
15+
getJda().awaitReady();
16+
}
17+
}
18+
```
19+
20+
## Commands
21+
Making commands with this framework is really easy, here's an example:
22+
23+
```java
24+
import com.seailz.jdaframework.command.Command;
25+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
26+
27+
public class CommandExample extends Command {
28+
@Override
29+
public void onCommand(SlashCommandInteractionEvent e) {
30+
e.reply("Hello World!").queue();
31+
}
32+
}
33+
```
34+
See? Really easy!
35+
Now all you need to do is register it in your main class, like this:
36+
```java
37+
registerCommands(
38+
new CommandExample()
39+
);
40+
```
41+
42+
## Modals
43+
44+
### QUICK DISCALIMER
45+
You **must** include this line in your main class:
46+
```java
47+
jdaInstanceVariable.addEventListener(new ModalListener());
48+
```
49+
50+
If you don't, it will not work.
51+
I may try to find a way around this in the future, but for now, that's how it is.
52+
53+
```java
54+
public class ModalExample extends Modal {
55+
56+
public ModalExample() {
57+
super("Questions", "age-question"); // The title and the ID
58+
TextInput input = TextInput.create("age", "How old are you?", TextInputStyle.SHORT)
59+
.setMaxLength(2).build(); // The input fields
60+
61+
addComponent(member -> input); // adds the component to the modal
62+
onSubmit((member, mappings, event) -> {
63+
event.reply("Thanks for submitting your age! We received **" + mappings[0].getAsString() + "** years old.").queue();
64+
}); // what to do when the modal is submitted
65+
}
66+
}
67+
```
68+
69+
Here's an example of opening a modal for a user:
70+
71+
```java
72+
public class ModalCommand extends ListenerAdapter {
73+
74+
@Override
75+
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
76+
if (!event.getName().equals("modal"))
77+
return;
78+
ModalExample testModal = new ModalExample();
79+
testModal.open(event.getMember(), event);
80+
}
81+
82+
}
83+
```

0 commit comments

Comments
 (0)