https://github.com/lni-dev/lapi
LApi is a Discord API written in Java
https://github.com/lni-dev/lapi
discord-api java lapi
Last synced: 3 months ago
JSON representation
LApi is a Discord API written in Java
- Host: GitHub
- URL: https://github.com/lni-dev/lapi
- Owner: lni-dev
- License: apache-2.0
- Archived: true
- Created: 2022-03-27T14:11:05.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T23:41:07.000Z (over 1 year ago)
- Last Synced: 2026-01-12T16:27:28.228Z (3 months ago)
- Topics: discord-api, java, lapi
- Language: Java
- Homepage:
- Size: 2.05 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LApi




LApi is a Discord API written in Java
Achived: No further development.
## Installation 
In order to install it, you can either build it yourself or use gradle and implement it into your Project:
In your `build.gradle` add `mavenCentral()` to the repositories if you have not done so already and add the following two dependencies. Replace `[version]` with the version you want to install.
```groovy
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'io.github.lni-dev:lapi-annotation-processor:1.0.1'
implementation 'io.github.lni-dev:lapi:[version]'
}
```
An example `build.gradle` could look like this:
```groovy
plugins {
id 'java'
}
group 'com.example'
version 'your.version'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'io.github.lni-dev:lapi-annotation-processor:1.0.1'
implementation 'io.github.lni-dev:lapi:1.0.4'
}
```
(Tested on gradle 7.5.1)
If you want to make an executable .jar file at some point in time, I recommend
the gradle plugins `application` and `shadow`. An example `build.gradle` with these plugins could
look like this:
```groovy
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
group 'com.example'
version '1.0.0'
mainClassName = 'com.example.exampleProjectName.Main'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'io.github.lni-dev:lapi-annotation-processor:1.0.1'
implementation 'io.github.lni-dev:lapi:1.0.4'
}
```
This will then add a gradle task called shadowJar, which will build an executable jar for you.
## Getting Started
First you will need to create a Discord bot and copy it's `TOKEN`.
Then you can create a Config:
```java
Config config = ConfigBuilder.getDefault("TOKEN", true).build();
```
And create a LApi instance:
```java
Config config = ConfigBuilder.getDefault("TOKEN", true).build();
LApi lApi = LApi.newInstance(config);
```
Or a lot simpler:
```java
LApi lApi = ConfigBuilder.getDefault("TOKEN", true).buildLApi();
```
`TOKEN` must be replaced with your bot token. The second boolean parameter specifies, whether
you want the privileged intents enabled. Read more [here](https://discord.com/developers/docs/topics/gateway#privileged-intents).
If you pass `true`, you have to enable them for your application's bot [here](https://discord.com/developers/applications).
Now you can register an EventListener:
```java
lApi.getEventTransmitter().addListener(new EventListener() {
@Override
public void onMessageCreate(@NotNull LApi lApi, @NotNull MessageCreateEvent event) {
//code
}
@Override
public void onMessageUpdate(@NotNull LApi lApi, @NotNull MessageUpdateEvent event) {
//code
}
@Override
public void onMessageDelete(@NotNull LApi lApi, @NotNull MessageDeleteEvent event) {
//code
}
});
```
Inside your listener, you can overwrite all events, you want to listen to.
Here a small example on how to respond to "Hi":
```java
lApi.getEventTransmitter().addListener(new EventListener() {
@Override
public void onMessageCreate(@NotNull LApi lApi, @NotNull MessageCreateEvent event) {
System.out.println("Message: " + event.getMessage().getContent());
if(!event.getMessage().getAuthor().isBot() && event.getMessage().getContent().equals("Hi")){
lApi.getRequestFactory().createMessage(event.getChannelId(), "Hi").queue();
}
}
});
```
Note the check, if the message was sent by a bot. This check is important, so that your bot does not respond to itself.