Skip to content

Commit

Permalink
Upgrade to JDA 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyoondotcom committed Apr 19, 2023
1 parent 852c633 commit f157b06
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ buildNumber.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
.idea/

.DS_Store
2 changes: 0 additions & 2 deletions MinecraftManhunt/.idea/MinecraftManhunt.iml

This file was deleted.

4 changes: 2 additions & 2 deletions MinecraftManhunt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.1_253</version>
<version>5.0.0-beta.8</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -86,7 +86,7 @@
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.75</version>
<version>1.3.77</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.requests.GatewayIntent;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import sun.reflect.annotation.ExceptionProxy;

import javax.security.auth.login.LoginException;
import java.util.List;

public class DiscordManager extends ListenerAdapter {
Expand All @@ -42,15 +40,11 @@ public DiscordManager(PluginMain main) {
String presenceMessage = config.getString("ip", "");

if(enabled){
JDABuilder builder = JDABuilder.createDefault(discordToken);
JDABuilder builder = JDABuilder.create(discordToken, GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_VOICE_STATES);
if(presenceMessage.length() > 0) {
builder.setActivity(Activity.playing(presenceMessage));
}
try {
client = builder.build();
} catch (LoginException e) {
main.logger.warning("LoginException: Discord token is invalid. " + e.getMessage());
}
client = builder.build();
client.addEventListener(this);
}
}
Expand Down Expand Up @@ -159,8 +153,9 @@ public boolean removeRoles(String username){
}

@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if(event.getAuthor().isBot()) return;
if(!event.isFromGuild()) return;
if(!processDiscordCommands) return;
if(!event.getGuild().getId().equalsIgnoreCase(guild.getId())) return;
String message = event.getMessage().getContentDisplay().trim().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sun.media.jfxmedia.logging.Logger;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.managers.AudioManager;
import org.bukkit.configuration.file.FileConfiguration;

Expand Down Expand Up @@ -36,7 +35,7 @@ public void Connect(){
main.logger.warning("Music channel ID not specified in config.");
return;
}
VoiceChannel vc = audioManager.getGuild().getVoiceChannelById(voiceId);
AudioChannel vc = audioManager.getGuild().getVoiceChannelById(voiceId);
if(vc == null){
main.logger.warning("Voice channel with id " + voiceId + " does not exist.");
return;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Hunters try to kill the runners before they beat the enderdragon. Runners must b
### Discord Setup Instructions
- Create a Discord app from the [Developer Portal](https://discord.com/developers/applications).
- Add a Bot under the bots tab.
- Scroll down and enable the toggles under "server members intent" and "message content intent".
- Take note of your **Client ID** (in the General Information tab) and your **Token** (under the Bot tab).
- Go to the following link, replacing `123YourClientID456` with your client ID: `https://discord.com/oauth2/authorize?scope=bot&client_id=123YourClientID456&permissions=8`
- Select the Discord server to add your bot to.
Expand Down

0 comments on commit f157b06

Please sign in to comment.