문서:JDA

역사 raw
대문 랜덤 문서 최근 토론


Java Discord API
최신 버전
4.2.0_228[2]
1. 개요2. 설치
2.1. [[Maven]]2.2. Gradle
3. 예제
3.1. Ping Bot

1. 개요

Discord API를 자바에서 간편하게 쓸 수 있는 비공식 라이브러리다.
자바 비공식 라이브러리들중에 JDA 라이브러리가 가장 인기가 많다.

2. 설치

VERSION를 버전으로 바꿔 적으면 된다.

2.1. Maven


<dependency>
    <groupId>net.dv8tion</groupId>
    <artifactId>JDA</artifactId>
    <version>VERSION</version>
</dependency>


<repository>
    <id>jcenter</id>
    <name>jcenter-bintray</name>
    <url>https://jcenter.bintray.com</url>
</repository>


오디오 모듈없이 설치

<dependency>
    <groupId>net.dv8tion</groupId>
    <artifactId>JDA</artifactId>
    <version>VERSION</version>
    <exclusions>
        <exclusion>
            <groupId>club.minnced</groupId>
            <artifactId>opus-java</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2.2. Gradle


dependencies {
    compile 'net.dv8tion:JDA:VERSION'
}

repositories {
    jcenter()
}


오디오 모듈없이 설치

dependencies {
    compile ('net.dv8tion:JDA:VERSION') {
        exclude module: 'opus-java'
    }
}


3. 예제

간단한 예제들이다.
예제를 작성할 때 가능하면 최신버전기준으로 해주십시오.

3.1. Ping Bot

public class NamuWikiBot extends ListenerAdapter {

    public static void main(String[] args) throws LoginException {

        // 기본 jda를 만들고
        JDA jda = JDABuilder.createDefault("토큰").build();

        // jda에 이벤트를 감지하는 리스너를 넣는다.
        jda.addEventListener(new NamuWikiBot());
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event) {

        // 받은 메세지 내용이 ping이라면
        if (event.getMessage().getContentRaw().equals("!ping")) {
            // pong라는 내용을 보낸다.
            event.getChannel().sendMessage("pong!").queue();
        }
    }
}
[1] 2021-2-19 기준[2] 2021-2-19 기준