Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the getting started section to be easier to read and follow. #33

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/introduction/faq.md → docs/getting-started/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Didn't find an answer? Try asking in [our Discord server](https://discord.gg/0hM

We currently provide a fallback implementation to not lose logging completely in this case. This fallback does not allow for a lot of configuration and we suggest using a proper implementation instead.

I recommend [Logback](https://logback.qos.ch/). You can just add it to your Gradle/Maven file as extra dependency. There is a basic setup guide in our wiki available here: [Logging Setup](../setup/logging.md)
I recommend [Logback](https://logback.qos.ch/). You can just add it to your Gradle/Maven file as extra dependency. There is a basic setup guide in our wiki available here: [Logging Setup](./logging.md)

??? question "What is the best way to delete messages from history?"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
143 changes: 143 additions & 0 deletions docs/getting-started/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# JDA (Java Discord API)

This page provides a fast introduction to JDA. For a more comprehensive guide, please view [the setup guide](../using-jda/getting-started.md).

## Download
Whilst downloads are available on the [Jenkins Server](https://ci.dv8tion.net/job/JDA5/) and the [JDA GitHub releases](https://github.com/DV8FromTheWorld/JDA/releases) pages,
it is highly recommended to use a build tool like Gradle or Maven to manage JDA and its dependencies.

!!! Information ""
=== "Maven"
```xml
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>VERSION</version>
</dependency>
```
=== "Maven (No Audio)"
```xml
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>VERSION</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
</dependency>
```
=== "Gradle"
```groovy
repositories {
mavenCentral()
}

dependencies {
implementation("net.dv8tion:JDA:VERSION")
}
```
=== "Gradle (No Audio)"
```groovy
repositories {
mavenCentral()
}

dependencies {
implementation("net.dv8tion:JDA:VERSION") {
exclude module: 'opus-java'
}
}
```
Remember to replace the `VERSION` with the version you would like to use. Version information can be found from
[JDA Discord Server](https://discord.gg/0hMr4ce0tIk3pSjp), [JDA GitHub](https://github.com/DV8FromTheWorld/JDA/releases) or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[JDA Discord Server](https://discord.gg/0hMr4ce0tIk3pSjp), [JDA GitHub](https://github.com/DV8FromTheWorld/JDA/releases) or
[JDA Discord Server](https://discord.gg/jda), [JDA GitHub](https://github.com/DV8FromTheWorld/JDA/releases) or

[Maven Central](https://mvnrepository.com/artifact/net.dv8tion/JDA/).

[![Download](https://img.shields.io/maven-central/v/net.dv8tion/JDA?color=blue)](https://ci.dv8tion.net/job/JDA5/lastSuccessfulBuild/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a link to maven central, pointing to latest ? The CI server could be going down at some point



## Minimal Examples
!!! example "Simple Ready Listener Example"
```java
public class ReadyListener implements ListenerAdapter
{
public static void main(String[] args)
throws LoginException
{
JDA jda = JDABuilder.createDefault(BOT_TOKEN)
.addEventListeners(new ReadyListener()).build();
}

@Override
public void onReady(ReadyEvent event)
{
System.out.println("JDA has started!");
}
}
```

!!! example "Simple Message Logging Example"
```java
public class MessageListener extends ListenerAdapter
{
public static void main(String[] args)
throws LoginException
{
JDA jda = JDABuilder.createDefault(BOT_TOKEN)
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
.build();
jda.addEventListeners(new MessageListener());
}

@Override
public void onMessageReceived(MessageReceivedEvent event)
{
if (event.isFromType(ChannelType.TEXT))
{
System.out.printf("[%s][%s] %#s: %s%n", event.getGuild().getName(),
event.getChannel().getName(), event.getAuthor(), event.getMessage().getContentDisplay());
}
else
{
System.out.printf("[PM] %#s: %s%n", event.getAuthor(), event.getMessage().getContentDisplay());
}
}
}
```
!!! information "More Examples"
We provide a small set of Examples in the [Example Directory](https://github.com/DV8FromTheWorld/JDA/tree/master/src/examples/java).


## Docs
You can find the [latest Javadocs](https://ci.dv8tion.net/job/JDA5/javadoc/) and the [legacy Javadocs](https://ci.dv8tion.net/job/JDA/javadoc/) on the Jenkins server.

For other versions of JDA, the javadocs jar can be downloaded from the version's page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do not recommend downloading any kind of javadocs jar


For example, the v4.2.0_200 javadocs can be found at:
<https://ci.dv8tion.net/job/JDA/200/>, which can be extracted for its docs.
Comment on lines +118 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should mention JDA 4 in this wiki


## Getting Help
If you need help, or just want to talk with the JDA or other Devs, you can join the [Official JDA Discord Guild](https://discord.gg/0hMr4ce0tIl3SLv5).

Alternatively, you can visit the `#java_jda` channel in the [Unofficial Discord API Guild](https://discord.gg/discord-api).
The dedicated JDA guild is generally more active, and will often help you faster.
<br>
For guides and setup help, this wiki aims to provide information.

If you're looking for guides or setup help, check out our [Getting Started](../using-jda/getting-started.md) pages.

## Contributing to JDA
If you want to contribute to JDA, make sure to base your branch off of our **master** branch (or a feature-branch)
and create your PR into that **same** branch.

It's recommended to ask (preferably in the JDA Guild) about a PR before starting one, to ensure that it is a welcome change and that it isn't already being worked on.

More information can be found on our [Contributing](../contributing/contributing.md) page.

We have dedicated library development and wiki development channels on our [Discord server](https://discord.gg/0hMr4ce0tIl3SLv5), where you can ask questions or suggest ideas.

## Dependencies
This project requires **Java 8**.<br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say you can use higher versions too

For other dependencies, see [README](https://github.com/DV8FromTheWorld/JDA5/tree/master/README.md)
94 changes: 0 additions & 94 deletions docs/introduction/jda.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ GenericGuildStickerEvent
└── GuildStickerUpdateTagsEvent
</pre>

[//]: # (todo: add interaction events )

[^1]: This extends UpdateEvent<br>
[^2]: This event needs to be explicitly enabled in the JDABuilder/DefaultShardManagerBuilder<br>
[^3]: This extends GenericUserPresenceEvent
55 changes: 29 additions & 26 deletions docs/introduction/events.md → docs/using-jda/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@

## Registering your Listener

To register your listener, we currently have 2 Systems. Annotated Listeners _(AnnotatedEventManager)_ and Listeners implementing the Interface _EventListener (InterfacedEventManager)_. By default, the Interfaced one is used.
JDA uses the observer pattern for its event system. In order to use events, a listener has to be used and registered with JDA.

To switch between them, you can either use `JDABuilder#setEventManager(new AnnotatedEventManager())`, or `JDA#setEventManager(new MyEventManager())`.
There are currently two systems for listeners: the default implementation which requires subclassing/implementing `EventListener` or `ListenerAdapter`, and an annotated listener `AnnotatedEventManager` which runs annotated methods based on their signature.

After that, you just need to call `JDABuilder#addEventListeners(Object...)` or `JDA#addEventListeners(Object...)` with your Listener implementation.
To switch between them, you can use `JDA#setEventManager(new InterfacedEventManager())` or `JDABuilder#setEventManager(new AnnotatedEventManager())`.

```java title="Using JDABuilder"
// imports {...}
public class Launcher
After that, you just need to call `JDABuilder#addEventListeners(Object...)` or `JDA#addEventListeners(Object...)` with your listeners.

Adding listeners to the `JDABuilder` as opposed to the `JDA` instance will ensure that all listeners will receive events during startup.
If the listeners are added after JDA is built, they will not receive any events that occurred before they were added.

```java
public class ExampleListener extends ListenerAdapter
{
public static void main(String[] arguments)
throws LoginException, InterruptedException
public static void main(String[] args) throws LoginException
{
JDA api = JDABuilder.createDefault(arguments[0])
.addEventListeners(new PingPongBot())
.build().awaitReady();
JDA jda = JDABuilder.createDefault(DISCORD_TOKEN)
.addEventListeners(new ExampleListener())
.build();
}
}
```

```java title="Using JDA"
// imports {...}
public class MyListeners
{
public static void registerPingPongListener(JDA api)

@Override
public void onReady(ReadyEvent event)
{
api.addEventListeners(new PingPongBot());
System.out.println("JDA Started!");
}
}
```
Expand All @@ -39,15 +37,22 @@ When using the interfaced system (default), your Listener(s) have to implement t

For convenience, we also included the class _ListenerAdapter_, which comes with a wide set of predefined functions targeted at specific event-types.

!!! Warning


!!! example "Examples"
Using `instanceof` checks is cumbersome, so JDA provides the `ListenerAdapter` to ease this.
```java title="Using EventListener"
public class Test implements EventListener
{
@Override
public void onEvent(GenericEvent event)
{
if(event instanceof MessageReceivedEvent)
System.out.println(event.getMessage().getContentDisplay());
if (event instanceof MessageReceivedEvent)
{
MessageReceivedEvent messageEvent = (MessageReceivedEvent) event;
System.out.println(messageEvent.getMessage().getContentDisplay());
}
}
}
```
Expand All @@ -61,12 +66,11 @@ For convenience, we also included the class _ListenerAdapter_, which comes with
}
}
```
_Don't forget actually registering this listener_


## Using the Annotated System

When using the annotated system, all listener methods have to have the `@SubscribeEvent` annotation present, and only accept a single parameter, which has to be a instance of _Event_.
When using the annotated system, all listener methods have to have the `@SubscribeEvent` annotation present, and only accept a single parameter, which has to be an implementation of _Event_.

!!! example
```java
Expand All @@ -87,5 +91,4 @@ When using the annotated system, all listener methods have to have the `@Subscri
System.out.println(event.getMessage().getContentDisplay());
}
}
```
_Don't forget actually registering this listener_
```
Loading