Added InviteCommand

This commit is contained in:
Joel 2021-02-20 00:27:35 +01:00
parent 7255024b68
commit 771982ed19
2 changed files with 45 additions and 0 deletions

View File

@ -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)

View File

@ -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<String> 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!");
});
}
}