Search in sources :

Example 21 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.

the class KickCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    Member sender = event.getMember();
    Guild guild = event.getGuild();
    if (guild == null)
        return;
    Member member = event.getOption("user").getAsMember();
    String reason = event.getOption("reason") == null ? null : event.getOption("reason").getAsString();
    if (member == null) {
        event.replyEmbeds(EmbedUtil.errorEmbed("This user is not member of this guild!")).setEphemeral(true).queue();
        return;
    }
    if (sender.getIdLong() == member.getIdLong()) {
        ctx.reply(EmbedUtil.errorEmbed("You cannot kick yourself!")).setEphemeral(true).queue();
        return;
    }
    if (!sender.canInteract(member)) {
        ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.kick.you_cannot_kick"))).setEphemeral(true).queue();
        return;
    }
    if (ctx.getGuildData().isModerator(member)) {
        ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.kick.you_cannot_kick_moderator"))).setEphemeral(true).queue();
        return;
    }
    if (!guild.getSelfMember().canInteract(member)) {
        ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.kick.i_cannot_kick"))).setEphemeral(true).queue();
        return;
    }
    MessageEmbed confirmationEmbed = new EmbedBuilder().setColor(EmbedUtil.SUCCESS_COLOR).setAuthor(ctx.getLocalized("commands.kick.has_been_kicked", member.getUser().getAsTag()), null, member.getUser().getEffectiveAvatarUrl()).addField(ctx.getLocalized("commands.reason"), reason == null ? ctx.getLocalized("commands.noreason") : reason, true).build();
    EmbedBuilder dmEmbed = new EmbedBuilder().setColor(CaseType.KICK.getEmbedColor()).setAuthor(ctx.getLocalized("commands.kick.you_have_been_kicked", guild.getName()), null, guild.getIconUrl()).addField("Moderator", sender.getAsMention() + " (" + sender.getUser().getAsTag() + ")", true);
    if (reason != null)
        dmEmbed.addField(ctx.getLocalized("commands.reason"), reason, true);
    event.deferReply(true).flatMap(hook -> member.getUser().openPrivateChannel()).flatMap(channel -> channel.sendMessageEmbeds(dmEmbed.build())).mapToResult().flatMap(hook -> guild.kick(member, reason)).flatMap(x -> event.getHook().sendMessageEmbeds(confirmationEmbed)).queue(x -> {
        ModCase.createModCase(CaseType.KICK, guild.getIdLong(), member.getIdLong(), sender.getIdLong(), reason);
        if (ctx.getGuildData().getLogChannel() != null) {
            TextChannel logChannel = ctx.getGuildData().getLogChannel();
            MessageEmbed logEmbed = new EmbedBuilder().setColor(CaseType.KICK.getEmbedColor()).setAuthor("Kick • " + member.getUser().getAsTag(), null, member.getUser().getEffectiveAvatarUrl()).addField(ctx.getLocalized("commands.reason"), reason == null ? ctx.getLocalized("commands.noreason") : reason, true).addField("Moderator", sender.getAsMention() + " (" + sender.getUser().getAsTag() + ")", true).setFooter(ctx.getLocalized("commands.user_id", member.getIdLong())).build();
            logChannel.sendMessageEmbeds(logEmbed).queue(s -> {
            }, e -> {
            });
        }
    }, e -> event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(ctx.getLocalized("general.unknown_error_occured"))).setEphemeral(true).queue());
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) Permission(net.dv8tion.jda.api.Permission) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) CaseType(at.xirado.bean.moderation.CaseType) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) ModCase(at.xirado.bean.moderation.ModCase) Commands(net.dv8tion.jda.api.interactions.commands.build.Commands) Guild(net.dv8tion.jda.api.entities.Guild) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) SlashCommand(at.xirado.bean.command.SlashCommand) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) NotNull(org.jetbrains.annotations.NotNull) EmbedUtil(at.xirado.bean.misc.EmbedUtil) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) TextChannel(net.dv8tion.jda.api.entities.TextChannel) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member)

Example 22 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.

the class SoftbanCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    Member sender = event.getMember();
    Guild guild = event.getGuild();
    if (guild == null) {
        LOGGER.error("Received /softban command with empty guild!");
        return;
    }
    OptionMapping memberOption = event.getOption("member");
    if (memberOption.getAsMember() == null) {
        ctx.replyError(ctx.getLocalized("commands.user_not_in_guild")).setEphemeral(true).queue();
        return;
    }
    String reason = event.getOption("reason") == null ? null : event.getOption("reason").getAsString();
    String reasonString = reason == null ? ctx.getLocalized("commands.noreason") : reason;
    Member member = memberOption.getAsMember();
    if (sender.getIdLong() == member.getIdLong()) {
        ctx.reply(EmbedUtil.errorEmbed(ctx.getLocalized("commands.ban.cannot_ban_self"))).setEphemeral(true).queue();
        return;
    }
    if (!sender.canInteract(member)) {
        ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.ban.you_cannot_ban_this_member"))).setEphemeral(true).queue();
        return;
    }
    if (ctx.getGuildData().isModerator(member)) {
        ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.ban.cannot_ban_moderator"))).setEphemeral(true).queue();
        return;
    }
    if (!guild.getSelfMember().canInteract(member)) {
        ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.ban.i_cannot_ban_this_member"))).setEphemeral(true).queue();
        return;
    }
    EmbedBuilder dmEmbed = new EmbedBuilder().setColor(CaseType.SOFTBAN.getEmbedColor()).setAuthor(ctx.getLocalized("commands.softban.you_have_been_softbanned", guild.getName()), null, guild.getIconUrl()).addField("Moderator", sender.getAsMention() + " (" + sender.getUser().getAsTag() + ")", true);
    if (reason != null)
        dmEmbed.addField(ctx.getLocalized("commands.reason"), reasonString, true);
    event.deferReply(true).flatMap(hook -> member.getUser().openPrivateChannel()).flatMap(channel -> channel.sendMessageEmbeds(dmEmbed.build())).mapToResult().flatMap(message -> guild.ban(member, 7)).flatMap(x -> guild.unban(member.getId())).queue(x -> {
        ModCase.createModCase(CaseType.SOFTBAN, guild.getIdLong(), member.getIdLong(), sender.getIdLong(), reason);
        MessageEmbed confirmationEmbed = new EmbedBuilder().setColor(EmbedUtil.SUCCESS_COLOR).setAuthor(ctx.getLocalized("commands.softban.has_been_softbanned", member.getUser().getAsTag()), null, member.getUser().getEffectiveAvatarUrl()).addField(ctx.getLocalized("commands.reason"), reasonString, true).build();
        event.getHook().sendMessageEmbeds(confirmationEmbed).queue();
        if (ctx.getGuildData().getLogChannel() != null) {
            TextChannel logChannel = ctx.getGuildData().getLogChannel();
            MessageEmbed logEmbed = new EmbedBuilder().setColor(CaseType.SOFTBAN.getEmbedColor()).setAuthor("Softban • " + member.getUser().getAsTag(), null, member.getUser().getEffectiveAvatarUrl()).addField(ctx.getLocalized("commands.reason"), reasonString, true).addField("Moderator", sender.getAsMention() + " (" + sender.getUser().getAsTag() + ")", true).setFooter(ctx.getLocalized("commands.user_id", member.getIdLong())).build();
            logChannel.sendMessageEmbeds(logEmbed).queue(s -> {
            }, e -> {
            });
        }
    }, e -> event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(ctx.getLocalized("general.unknown_error_occured"))).setEphemeral(true).queue());
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) Logger(org.slf4j.Logger) Permission(net.dv8tion.jda.api.Permission) LoggerFactory(org.slf4j.LoggerFactory) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) CaseType(at.xirado.bean.moderation.CaseType) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) ModCase(at.xirado.bean.moderation.ModCase) Commands(net.dv8tion.jda.api.interactions.commands.build.Commands) Guild(net.dv8tion.jda.api.entities.Guild) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) SlashCommand(at.xirado.bean.command.SlashCommand) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Bean(at.xirado.bean.Bean) NotNull(org.jetbrains.annotations.NotNull) EmbedUtil(at.xirado.bean.misc.EmbedUtil) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) TextChannel(net.dv8tion.jda.api.entities.TextChannel) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member)

Example 23 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method loadAndPlay.

public void loadAndPlay(final GenericInteractionCreateEvent event, Guild guild, final String trackUrl, boolean search, boolean playNow, SelectMenuInteractionEvent SelectMenuInteractionEvent) {
    List<String> lang = Main.language.getGuildLang(guild.getId());
    VoiceChannel vc = (VoiceChannel) event.getMember().getVoiceState().getChannel();
    GuildMusicManager manager = getMusicManager(jda.getGuildById(guild.getId()));
    // 取得音樂
    playerManager.loadItemOrdered(musicManagers, trackUrl, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            play(track, vc, manager, event, search, playNow, SelectMenuInteractionEvent);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            play(playlist, vc, manager, event, playNow);
        }

        @Override
        public void noMatches() {
            try {
                if (event instanceof SelectMenuInteractionEvent)
                    ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_URL_NOT_FOUND) + ": " + trackUrl, 0xFF0000)).queue();
                else if (event instanceof SlashCommandInteractionEvent)
                    ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_URL_NOT_FOUND) + ": " + trackUrl, 0xFF0000)).queue();
            } catch (Exception ignored) {
            }
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            try {
                if (event instanceof SelectMenuInteractionEvent)
                    ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_CANT_PLAY_URL) + ": " + exception.getMessage(), 0xFF0000)).queue();
                else if (event instanceof SlashCommandInteractionEvent)
                    ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_CANT_PLAY_URL) + ": " + exception.getMessage(), 0xFF0000)).queue();
            } catch (Exception ignored) {
            }
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) SelectMenuInteractionEvent(net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent) GuildMusicManager(com.ice.multiBot.music.GuildMusicManager) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 24 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class Ban method onCommand.

public void onCommand(SlashCommandInteractionEvent event) {
    if (!permissionCheck(BAN_MEMBERS, event, true))
        return;
    List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
    User user = event.getOption(USER_TAG).getAsUser();
    // Member member = event.getGuild().retrieveMemberById(user.getId()).complete();
    Member selfMember = event.getGuild().getSelfMember();
    if (!selfMember.hasPermission(BAN_MEMBERS)) {
        event.getHook().editOriginalEmbeds(createEmbed(lang.get(BAN_NO_PERMISSION), 0xFF0000)).queue();
        return;
    }
    if (botOwnerID.contains(user.getId())) {
        event.getHook().editOriginalEmbeds(createEmbed(lang.get(BAN_DEVELOPER), 0xFF0000)).queue();
        return;
    }
    // if (event.getGuild().retrieveBanList().complete().contains(user)) {
    int delDays = 0;
    OptionMapping option = event.getOption(DAYS);
    if (option != null)
        delDays = (int) Math.max(0, Math.min(7, option.getAsLong()));
    event.getGuild().ban(user, delDays).flatMap(v -> event.getHook().editOriginalEmbeds(createEmbed(lang.get(BAN_SUCCESS) + ' ' + user.getAsTag(), 0xffb1b3))).queue();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) USER_TAG(com.ice.main.util.SlashCommandOption.USER_TAG) LangKey(com.ice.main.lang.LangKey) Main(com.ice.main.Main) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) Member(net.dv8tion.jda.api.entities.Member) BotSetting.botOwnerID(com.ice.main.BotSetting.botOwnerID) EmbedCreator.createEmbed(com.ice.main.util.EmbedCreator.createEmbed) User(net.dv8tion.jda.api.entities.User) BAN_MEMBERS(net.dv8tion.jda.api.Permission.BAN_MEMBERS) List(java.util.List) PermissionERROR.permissionCheck(com.ice.main.util.PermissionERROR.permissionCheck) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) DAYS(com.ice.main.util.SlashCommandOption.DAYS) User(net.dv8tion.jda.api.entities.User) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)24 Commands (net.dv8tion.jda.api.interactions.commands.build.Commands)11 NotNull (org.jetbrains.annotations.NotNull)11 SlashCommand (at.xirado.bean.command.SlashCommand)10 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)10 OptionType (net.dv8tion.jda.api.interactions.commands.OptionType)10 Permission (net.dv8tion.jda.api.Permission)9 EmbedUtil (at.xirado.bean.misc.EmbedUtil)7 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)7 Bean (at.xirado.bean.Bean)6 Guild (net.dv8tion.jda.api.entities.Guild)6 Member (net.dv8tion.jda.api.entities.Member)6 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)5 OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)5 ReplyCallbackAction (net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction)5 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Util (at.xirado.bean.misc.Util)3 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)3 SQLException (java.sql.SQLException)3