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());
}
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());
}
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) {
}
}
});
}
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();
}
Aggregations