diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java b/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java index 9bb66d3..ac2a2f2 100644 --- a/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java @@ -7,6 +7,7 @@ import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.requests.GatewayIntent; +import zone.themcgamer.discordbot.command.impl.InviteCommand; import zone.themcgamer.discordbot.command.impl.SetActivityCommand; import zone.themcgamer.discordbot.command.impl.SuggestCommand; import zone.themcgamer.discordbot.command.impl.ToggleNewsRoleCommand; @@ -37,6 +38,7 @@ public class MGZBot { commandClientBuilder.addCommand(new SuggestCommand()); commandClientBuilder.addCommand(new SetActivityCommand()); commandClientBuilder.addCommand(new ToggleNewsRoleCommand()); + commandClientBuilder.addCommand(new InviteCommand()); try { jda = JDABuilder.createDefault(BotConstants.TOKEN) diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/InviteCommand.java b/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/InviteCommand.java new file mode 100644 index 0000000..b5b9f3e --- /dev/null +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/InviteCommand.java @@ -0,0 +1,43 @@ +package zone.themcgamer.discordbot.command.impl; + +import com.jagrosh.jdautilities.command.CommandEvent; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.TextChannel; +import zone.themcgamer.discordbot.command.BaseCommand; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class InviteCommand extends BaseCommand { + + public InviteCommand() { + name = "invite"; + aliases = new String[]{"createinvite"}; + help = "Create invite link via the bot"; + guildOnly = true; + guilds = Collections.singletonList(zone.themcgamer.discordbot.guild.Guild.MAIN); + } + + @Override + protected void execute(CommandEvent event, List args) { + Guild guild = event.getGuild(); + + TextChannel textChannelById = guild.getTextChannelById(791015530001596456L); + if (textChannelById == null) + return; + textChannelById.createInvite() + .timeout(1, TimeUnit.DAYS) + .setTemporary(true).queue(inviteLink -> { + event.getMember().getUser().openPrivateChannel().queue(privateChannel -> { + privateChannel.sendMessage("I have generated an invite link for you! This invite link will work for 24 hours! " + inviteLink.getUrl()).queue(); + event.reply("Check your dm's!"); + }, error -> { + event.replyError("Could not sent you a dm!"); + }); }, error -> { + event.replyError("Coulnd't create an invite link due an error!"); + }); + + } +} \ No newline at end of file