From d37c83cb1b00f9328ea6b1ce6ac624773b05fe79 Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Sun, 19 Jun 2022 22:17:18 -0700 Subject: [PATCH 1/8] Add .env config loading --- .env.example | 1 + pom.xml | 6 ++++++ .../com/technovision/tutorialbot/TutorialBot.java | 12 +++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f74c661 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +TOKEN= \ No newline at end of file diff --git a/pom.xml b/pom.xml index dc7de8d..9c2f1dd 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,12 @@ JDA 5.0.0-alpha.12 + + + io.github.cdimascio + dotenv-java + 2.2.4 + \ No newline at end of file diff --git a/src/main/java/com/technovision/tutorialbot/TutorialBot.java b/src/main/java/com/technovision/tutorialbot/TutorialBot.java index af07e18..76e7742 100644 --- a/src/main/java/com/technovision/tutorialbot/TutorialBot.java +++ b/src/main/java/com/technovision/tutorialbot/TutorialBot.java @@ -1,5 +1,6 @@ package com.technovision.tutorialbot; +import io.github.cdimascio.dotenv.Dotenv; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; @@ -15,6 +16,7 @@ */ public class TutorialBot { + private final Dotenv config; private final ShardManager shardManager; /** @@ -22,13 +24,21 @@ public class TutorialBot { * @throws LoginException occurs when bot token is invalid. */ public TutorialBot() throws LoginException { - String token = "YOUR_BOT_TOKEN"; + config = Dotenv.configure().load(); + String token = config.get("TOKEN"); + DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.createDefault(token); builder.setStatus(OnlineStatus.ONLINE); builder.setActivity(Activity.watching("TechnoVisionTV")); shardManager = builder.build(); } + /** + * Retrieves the bot environment variables. + * @return the DotEnv instance for the bot. + */ + public Dotenv getConfig() { return config; } + /** * Retrieves the bot shard manager. * @return the ShardManager instance for the bot. From 08727561515e291d5261d4ea5d8daa1e23db4bfb Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Mon, 20 Jun 2022 00:47:55 -0700 Subject: [PATCH 2/8] Add event listener and gateway intents --- .../technovision/tutorialbot/TutorialBot.java | 8 +++ .../tutorialbot/listeners/EventListener.java | 65 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/main/java/com/technovision/tutorialbot/listeners/EventListener.java diff --git a/src/main/java/com/technovision/tutorialbot/TutorialBot.java b/src/main/java/com/technovision/tutorialbot/TutorialBot.java index 76e7742..e76b465 100644 --- a/src/main/java/com/technovision/tutorialbot/TutorialBot.java +++ b/src/main/java/com/technovision/tutorialbot/TutorialBot.java @@ -1,8 +1,10 @@ package com.technovision.tutorialbot; +import com.technovision.tutorialbot.listeners.EventListener; import io.github.cdimascio.dotenv.Dotenv; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; import net.dv8tion.jda.api.sharding.ShardManager; @@ -24,13 +26,19 @@ public class TutorialBot { * @throws LoginException occurs when bot token is invalid. */ public TutorialBot() throws LoginException { + // Load environment variables config = Dotenv.configure().load(); String token = config.get("TOKEN"); + // Build shard manager DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.createDefault(token); builder.setStatus(OnlineStatus.ONLINE); builder.setActivity(Activity.watching("TechnoVisionTV")); + builder.enableIntents(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES); shardManager = builder.build(); + + // Register listeners + shardManager.addEventListener(new EventListener()); } /** diff --git a/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java b/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java new file mode 100644 index 0000000..6dc682b --- /dev/null +++ b/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java @@ -0,0 +1,65 @@ +package com.technovision.tutorialbot.listeners; + +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; +import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +/** + * Listens for events and responds with our custom code. + * + * @author TechnoVision + */ +public class EventListener extends ListenerAdapter { + + /** + * Event fires when an emoji reaction is added to a message. + */ + @Override + public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { + User user = event.getUser(); + String jumpLink = event.getJumpUrl(); + String emoji = event.getReaction().getReactionEmote().getAsReactionCode(); + String channel = event.getChannel().getAsMention(); + + String message = user.getAsTag() + " reacted to a [message]("+jumpLink+") with " + emoji + " in the " + channel + " channel!"; + event.getGuild().getDefaultChannel().sendMessage(message).queue(); + } + + /** + * Event fires when a message is sent in discord. + * Warning: Will require "Guild Messages" gateway intent after August 2022! + */ + @Override + public void onMessageReceived(@NotNull MessageReceivedEvent event) { + // WILL NOT WORK WITHOUT GATEWAY INTENT! + String message = event.getMessage().getContentRaw(); + if (message.contains("ping")) { + event.getChannel().sendMessage("pong").queue(); + } + } + + /** + * Event fires when a new member joins a guild + * Warning: Will not work without "Guild Members" gateway intent! + */ + @Override + public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { + // WILL NOT WORK WITHOUT GATEWAY INTENT! + String avatar = event.getUser().getEffectiveAvatarUrl(); + System.out.println(avatar); + } + + /** + * Event fires when a role is added to a guild member. + * Warning: Will not work without "Guild Presences" gateway intent! + */ + @Override + public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { + // WILL NOT WORK WITHOUT GATEWAY INTENT! + event.getGuild().getDefaultChannel().sendMessage("Somebody got a new role!").queue(); + } +} From 1ef7dca92c6b0a0c30cff4f482189ce862237339 Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Mon, 20 Jun 2022 12:59:11 -0700 Subject: [PATCH 3/8] Add slash commands --- .../technovision/tutorialbot/TutorialBot.java | 3 +- .../tutorialbot/commands/CommandManager.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/technovision/tutorialbot/commands/CommandManager.java diff --git a/src/main/java/com/technovision/tutorialbot/TutorialBot.java b/src/main/java/com/technovision/tutorialbot/TutorialBot.java index e76b465..d7cebc7 100644 --- a/src/main/java/com/technovision/tutorialbot/TutorialBot.java +++ b/src/main/java/com/technovision/tutorialbot/TutorialBot.java @@ -1,5 +1,6 @@ package com.technovision.tutorialbot; +import com.technovision.tutorialbot.commands.CommandManager; import com.technovision.tutorialbot.listeners.EventListener; import io.github.cdimascio.dotenv.Dotenv; import net.dv8tion.jda.api.OnlineStatus; @@ -38,7 +39,7 @@ public TutorialBot() throws LoginException { shardManager = builder.build(); // Register listeners - shardManager.addEventListener(new EventListener()); + shardManager.addEventListener(new EventListener(), new CommandManager()); } /** diff --git a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java new file mode 100644 index 0000000..6762fb8 --- /dev/null +++ b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java @@ -0,0 +1,54 @@ +package com.technovision.tutorialbot.commands; + +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.events.guild.GuildReadyEvent; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; +import net.dv8tion.jda.api.interactions.commands.build.Commands; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * Registers and manages slash commands. + * + * @author TechnoVision + */ +public class CommandManager extends ListenerAdapter { + + /** + * Listens for slash commands and responds accordingly + */ + @Override + public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { + String command = event.getName(); + if (command.equals("welcome")) { + // Run the 'ping' command + String userTag = event.getUser().getAsTag(); + event.reply("Welcome to the server, **" + userTag + "**!").queue(); + } + else if (command.equals("roles")) { + // run the 'roles' command + event.deferReply().queue(); + String response = ""; + for (Role role : event.getGuild().getRoles()) { + response += role.getAsMention() + "\n"; + } + event.getHook().sendMessage(response).queue(); + } + } + + /** + * Registers slash commands as guild commands. + */ + @Override + public void onGuildReady(@NotNull GuildReadyEvent event) { + List commandData = new ArrayList<>(); + commandData.add(Commands.slash("welcome", "Get welcomed by the bot")); + commandData.add(Commands.slash("roles", "Display all roles on the server")); + + event.getGuild().updateCommands().addCommands(commandData).queue(); + } +} From b20ac751a4ca49e16b4c0ac23aa2dff083206231 Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Mon, 20 Jun 2022 15:05:07 -0700 Subject: [PATCH 4/8] Redo tutorial for intents --- .../technovision/tutorialbot/TutorialBot.java | 3 +- .../tutorialbot/commands/CommandManager.java | 54 ------------------- .../tutorialbot/listeners/EventListener.java | 27 +++++----- 3 files changed, 16 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/com/technovision/tutorialbot/commands/CommandManager.java diff --git a/src/main/java/com/technovision/tutorialbot/TutorialBot.java b/src/main/java/com/technovision/tutorialbot/TutorialBot.java index d7cebc7..e76b465 100644 --- a/src/main/java/com/technovision/tutorialbot/TutorialBot.java +++ b/src/main/java/com/technovision/tutorialbot/TutorialBot.java @@ -1,6 +1,5 @@ package com.technovision.tutorialbot; -import com.technovision.tutorialbot.commands.CommandManager; import com.technovision.tutorialbot.listeners.EventListener; import io.github.cdimascio.dotenv.Dotenv; import net.dv8tion.jda.api.OnlineStatus; @@ -39,7 +38,7 @@ public TutorialBot() throws LoginException { shardManager = builder.build(); // Register listeners - shardManager.addEventListener(new EventListener(), new CommandManager()); + shardManager.addEventListener(new EventListener()); } /** diff --git a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java deleted file mode 100644 index 6762fb8..0000000 --- a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.technovision.tutorialbot.commands; - -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.events.guild.GuildReadyEvent; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.api.interactions.commands.build.CommandData; -import net.dv8tion.jda.api.interactions.commands.build.Commands; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * Registers and manages slash commands. - * - * @author TechnoVision - */ -public class CommandManager extends ListenerAdapter { - - /** - * Listens for slash commands and responds accordingly - */ - @Override - public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { - String command = event.getName(); - if (command.equals("welcome")) { - // Run the 'ping' command - String userTag = event.getUser().getAsTag(); - event.reply("Welcome to the server, **" + userTag + "**!").queue(); - } - else if (command.equals("roles")) { - // run the 'roles' command - event.deferReply().queue(); - String response = ""; - for (Role role : event.getGuild().getRoles()) { - response += role.getAsMention() + "\n"; - } - event.getHook().sendMessage(response).queue(); - } - } - - /** - * Registers slash commands as guild commands. - */ - @Override - public void onGuildReady(@NotNull GuildReadyEvent event) { - List commandData = new ArrayList<>(); - commandData.add(Commands.slash("welcome", "Get welcomed by the bot")); - commandData.add(Commands.slash("roles", "Display all roles on the server")); - - event.getGuild().updateCommands().addCommands(commandData).queue(); - } -} diff --git a/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java b/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java index 6dc682b..355b500 100644 --- a/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java +++ b/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java @@ -1,10 +1,11 @@ package com.technovision.tutorialbot.listeners; +import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.api.events.user.update.UserUpdateOnlineStatusEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; @@ -31,11 +32,10 @@ public void onMessageReactionAdd(@NotNull MessageReactionAddEvent event) { /** * Event fires when a message is sent in discord. - * Warning: Will require "Guild Messages" gateway intent after August 2022! + * Will require "Guild Messages" gateway intent after August 2022! */ @Override public void onMessageReceived(@NotNull MessageReceivedEvent event) { - // WILL NOT WORK WITHOUT GATEWAY INTENT! String message = event.getMessage().getContentRaw(); if (message.contains("ping")) { event.getChannel().sendMessage("pong").queue(); @@ -44,22 +44,25 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { /** * Event fires when a new member joins a guild - * Warning: Will not work without "Guild Members" gateway intent! + * Requires "Guild Members" gateway intent! */ @Override public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { - // WILL NOT WORK WITHOUT GATEWAY INTENT! - String avatar = event.getUser().getEffectiveAvatarUrl(); - System.out.println(avatar); + Role role = event.getGuild().getRoleById(988342442430443540L); + if (role != null) { + event.getGuild().addRoleToMember(event.getMember(), role).queue(); + } } /** - * Event fires when a role is added to a guild member. - * Warning: Will not work without "Guild Presences" gateway intent! + * Event fires when a user updates their online status + * Requires "Guild Presences" gateway intent AND cache enabled! */ @Override - public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { - // WILL NOT WORK WITHOUT GATEWAY INTENT! - event.getGuild().getDefaultChannel().sendMessage("Somebody got a new role!").queue(); + public void onUserUpdateOnlineStatus(@NotNull UserUpdateOnlineStatusEvent event) { + // WILL NOT WORK WITHOUT USER CACHE (See Episode 5) + User user = event.getUser(); + String message = user.getAsTag() + " updated their online status!"; + event.getGuild().getDefaultChannel().sendMessage(message).queue(); } } From 8264dd3735ca634a0cdcc01252b4d99727981d58 Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Mon, 20 Jun 2022 15:11:02 -0700 Subject: [PATCH 5/8] Add member cache --- .../com/technovision/tutorialbot/TutorialBot.java | 6 ++++++ .../tutorialbot/listeners/EventListener.java | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/technovision/tutorialbot/TutorialBot.java b/src/main/java/com/technovision/tutorialbot/TutorialBot.java index e76b465..f1819c1 100644 --- a/src/main/java/com/technovision/tutorialbot/TutorialBot.java +++ b/src/main/java/com/technovision/tutorialbot/TutorialBot.java @@ -7,6 +7,9 @@ import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; import net.dv8tion.jda.api.sharding.ShardManager; +import net.dv8tion.jda.api.utils.ChunkingFilter; +import net.dv8tion.jda.api.utils.MemberCachePolicy; +import net.dv8tion.jda.api.utils.cache.CacheFlag; import javax.security.auth.login.LoginException; @@ -35,6 +38,9 @@ public TutorialBot() throws LoginException { builder.setStatus(OnlineStatus.ONLINE); builder.setActivity(Activity.watching("TechnoVisionTV")); builder.enableIntents(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES); + builder.setMemberCachePolicy(MemberCachePolicy.ALL); + builder.setChunkingFilter(ChunkingFilter.ALL); + builder.enableCache(CacheFlag.ONLINE_STATUS); shardManager = builder.build(); // Register listeners diff --git a/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java b/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java index 355b500..e3838d8 100644 --- a/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java +++ b/src/main/java/com/technovision/tutorialbot/listeners/EventListener.java @@ -1,5 +1,7 @@ package com.technovision.tutorialbot.listeners; +import net.dv8tion.jda.api.OnlineStatus; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; @@ -60,9 +62,13 @@ public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { */ @Override public void onUserUpdateOnlineStatus(@NotNull UserUpdateOnlineStatusEvent event) { - // WILL NOT WORK WITHOUT USER CACHE (See Episode 5) - User user = event.getUser(); - String message = user.getAsTag() + " updated their online status!"; + int onlineMembers = 0; + for (Member member : event.getGuild().getMembers()) { + if (member.getOnlineStatus() == OnlineStatus.ONLINE) { + onlineMembers++; + } + } + String message = event.getUser().getAsTag()+"updated their online status! There are "+onlineMembers+" members online now!"; event.getGuild().getDefaultChannel().sendMessage(message).queue(); } } From feb80aa1fdd3c203719784a5851031b6bca29acd Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Mon, 20 Jun 2022 15:13:33 -0700 Subject: [PATCH 6/8] Add guild commands --- .../technovision/tutorialbot/TutorialBot.java | 3 +- .../tutorialbot/commands/CommandManager.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/technovision/tutorialbot/commands/CommandManager.java diff --git a/src/main/java/com/technovision/tutorialbot/TutorialBot.java b/src/main/java/com/technovision/tutorialbot/TutorialBot.java index f1819c1..d3259b6 100644 --- a/src/main/java/com/technovision/tutorialbot/TutorialBot.java +++ b/src/main/java/com/technovision/tutorialbot/TutorialBot.java @@ -1,5 +1,6 @@ package com.technovision.tutorialbot; +import com.technovision.tutorialbot.commands.CommandManager; import com.technovision.tutorialbot.listeners.EventListener; import io.github.cdimascio.dotenv.Dotenv; import net.dv8tion.jda.api.OnlineStatus; @@ -44,7 +45,7 @@ public TutorialBot() throws LoginException { shardManager = builder.build(); // Register listeners - shardManager.addEventListener(new EventListener()); + shardManager.addEventListener(new EventListener(), new CommandManager()); } /** diff --git a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java new file mode 100644 index 0000000..3b47923 --- /dev/null +++ b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java @@ -0,0 +1,54 @@ +package com.technovision.tutorialbot.commands; + +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.events.guild.GuildReadyEvent; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; +import net.dv8tion.jda.api.interactions.commands.build.Commands; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * Registers and manages slash commands. + * + * @author TechnoVision + */ +public class CommandManager extends ListenerAdapter { + + /** + * Listens for slash commands and responds accordingly + */ + @Override + public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { + String command = event.getName(); + if (command.equals("welcome")) { + // Run the 'ping' command + String userTag = event.getUser().getAsTag(); + event.reply("Welcome to the server, **" + userTag + "**!").queue(); + } + else if (command.equals("roles")) { + // run the 'roles' command + event.deferReply().queue(); + String response = ""; + for (Role role : event.getGuild().getRoles()) { + response += role.getAsMention() + "\n"; + } + event.getHook().sendMessage(response).queue(); + } + } + + /** + * Registers slash commands as guild commands. + */ + @Override + public void onGuildReady(@NotNull GuildReadyEvent event) { + List commandData = new ArrayList<>(); + commandData.add(Commands.slash("welcome", "Get welcomed by the bot")); + commandData.add(Commands.slash("roles", "Display all roles on the server")); + + event.getGuild().updateCommands().addCommands(commandData).queue(); + } +} \ No newline at end of file From a30bb8369a1cb0b0d862196cbd8bf15ae804ddbf Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Sat, 25 Jun 2022 21:35:32 -0700 Subject: [PATCH 7/8] Add global command registration example --- .../tutorialbot/commands/CommandManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java index 3b47923..ce2d7db 100644 --- a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java +++ b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java @@ -1,6 +1,7 @@ package com.technovision.tutorialbot.commands; import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.events.ReadyEvent; import net.dv8tion.jda.api.events.guild.GuildReadyEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; @@ -41,14 +42,26 @@ else if (command.equals("roles")) { } /** - * Registers slash commands as guild commands. + * Registers slash commands as GUILD commands (max 100). + * These commands will update instantly and are great for testing. */ @Override public void onGuildReady(@NotNull GuildReadyEvent event) { List commandData = new ArrayList<>(); commandData.add(Commands.slash("welcome", "Get welcomed by the bot")); commandData.add(Commands.slash("roles", "Display all roles on the server")); - event.getGuild().updateCommands().addCommands(commandData).queue(); } + + /** + * Registers slash commands as GLOBAL commands (unlimited). + * These commands will take an hour to update. + */ + @Override + public void onReady(@NotNull ReadyEvent event) { + List commandData = new ArrayList<>(); + commandData.add(Commands.slash("welcome", "Get welcomed by the bot")); + commandData.add(Commands.slash("roles", "Display all roles on the server")); + event.getJDA().updateCommands().addCommands(commandData).queue(); + } } \ No newline at end of file From 43c34bb8c7f48a4cf67ace6b63a32805c85037a4 Mon Sep 17 00:00:00 2001 From: TechnoVisionDev Date: Sat, 25 Jun 2022 21:37:42 -0700 Subject: [PATCH 8/8] Update javadoc --- .../com/technovision/tutorialbot/commands/CommandManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java index ce2d7db..7a0c8cd 100644 --- a/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java +++ b/src/main/java/com/technovision/tutorialbot/commands/CommandManager.java @@ -55,7 +55,7 @@ public void onGuildReady(@NotNull GuildReadyEvent event) { /** * Registers slash commands as GLOBAL commands (unlimited). - * These commands will take an hour to update. + * These commands may take up to an hour to update. */ @Override public void onReady(@NotNull ReadyEvent event) {