JDA

덤프버전 :

분류


Java Discord API

파일:JDA logo.png

LTS 버전
4.4.0_352[1]
최신 버전
5.0.0-beta.9[2]
링크
파일:GitHub 아이콘.svg[[파일:GitHub 아이콘 화이트.svg
,파일:디스코드 아이콘.svg, Javadoc

1. 개요
2. 설치
3. 예제
3.1. Ping Bot




1. 개요[편집]


JDA(Java Discord API)는 Discord API를 Java로 래핑한 라이브러리다. 이 라이브러리를 사용하면 Java로 Discord 봇을 쉽게 개발할 수 있으며, Java 기반 Discord API Wrapper 라이브러리 중 가장 많이 사용되는 라이브러리 중 하나이다.


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 Bot extends ListenerAdapter
{
    public static void main(String[] args) throws LoginException
    {
        if (args.length < 1) {
            System.out.println("You have to provide a token as first argument!");
            System.exit(1);
        }
        JDABuilder.createLight(args[0], GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
            .addEventListeners(new Bot())
            .setActivity(Activity.playing("Type !ping"))
            .build();
    }
    
    @Override
    public void onMessageReceived(MessageReceivedEvent event)
    {
        Message msg = event.getMessage();
        if (msg.getContentRaw().equals("!ping"))
        {
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            channel.sendMessage("Pong!")
                   .queue(response -> {
                       response.editMessageFormat("Pong: %d ms", System.currentTimeMillis() - time).queue();
                   });
        }
    }
}

파일:크리에이티브 커먼즈 라이선스__CC.png 이 문서의 내용 중 전체 또는 일부는 2023-10-28 06:56:45에 나무위키 JDA 문서에서 가져왔습니다.

[1] 2022. 03. 08 기준[2] 2023. 05. 10 기준