JAVA 자료
[Maven] Discord와 Spigot(1.12.2)을 연동해보자.
SUN5066
2020. 6. 14. 17:12
반응형
[그림 5] 의 내용
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.like.sun.discord</groupId>
<artifactId>DiscordBot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DiscordBot</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.1_157</version>
</dependency>
</dependencies>
</project>
위 내용을 전체 복사 하던지.
[그림 1] ~ [그림 4] 까지 필자와 똑같이 설정했다면,
위 내용 그대로 복붙해도 상관없다.
혹은,
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.1_157</version>
</dependency>
위 내용만 복사해서 직접 넣던지 알아서 할것.
public static JDA jda;
public static void startBot() {
JDABuilder jb = new JDABuilder(AccountType.BOT);
jb.setAutoReconnect(true);
jb.setStatus(OnlineStatus.ONLINE);
jb.setToken("Token 입력");
jb.addEventListeners(new BotListener());
try {
jda = jb.build();
} catch (LoginException e) {
e.printStackTrace();
}
}
@Override
public void onMessageReceived(MessageReceivedEvent e) {
User user = e.getAuthor();
TextChannel tc = e.getTextChannel();
Message msg = e.getMessage();
if (user.isBot()) return;
tc.sendMessage(msg).queue();
tc.sendMessage(user.getAvatarId()).queue();
String MsgContentRaw = msg.getContentRaw();
String userName = user.getName();
Bukkit.broadcastMessage(String.format("§9§l[Discord] §f< %s > %s", userName, MsgContentRaw));
}
결과.
[개발자 GitHub] https://github.com/sun5066
sun5066 - Overview
sun5066 has 2 repositories available. Follow their code on GitHub.
github.com
[다운로드] https://github.com/sun5066/Discord-Spigot-Bot-Example
sun5066/Discord-Spigot-Bot-Example
디스코드, 스피갓 연동 예제. Contribute to sun5066/Discord-Spigot-Bot-Example development by creating an account on GitHub.
github.com
반응형