use of net.dv8tion.jda.api.entities.GuildVoiceState in project discord-bot-reddit-java by Glaxier0.
the class PauseCommand method execute.
@Override
public void execute(SlashCommandInteractionEvent event) {
GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
GuildVoiceState userVoiceState = event.getMember().getVoiceState();
if (utils.channelControl(botVoiceState, userVoiceState)) {
EmbedBuilder embedBuilder = new EmbedBuilder();
PlayerManager.getInstance().getMusicManager(event).audioPlayer.setPaused(true);
event.replyEmbeds(embedBuilder.setDescription("Song paused").setColor(Color.GREEN).build()).queue();
} else {
event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
}
net.dv8tion.jda.api.entities.User user = event.getUser();
utils.counter(user.getId(), user.getAsTag());
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project discord-bot-reddit-java by Glaxier0.
the class ResumeCommand method execute.
@Override
public void execute(SlashCommandInteractionEvent event) {
GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
GuildVoiceState userVoiceState = event.getMember().getVoiceState();
if (utils.channelControl(botVoiceState, userVoiceState)) {
EmbedBuilder embedBuilder = new EmbedBuilder();
PlayerManager.getInstance().getMusicManager(event).audioPlayer.setPaused(false);
event.replyEmbeds(embedBuilder.setDescription("Song resumed").setColor(Color.GREEN).build()).queue();
} else {
event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
}
net.dv8tion.jda.api.entities.User user = event.getUser();
utils.counter(user.getId(), user.getAsTag());
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.
the class ShhCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
final VoiceChannel memberChannel = memberVoiceState.getChannel();
memberChannel.getMembers().forEach(target -> {
if (!member.canInteract(target) || !member.hasPermission(Permission.VOICE_MUTE_OTHERS) || !requestingUserDto.isSuperUser()) {
channel.sendMessage(String.format("You aren't allowed to mute %s", target)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
final Member bot = ctx.getSelfMember();
if (!bot.hasPermission(Permission.VOICE_MUTE_OTHERS)) {
channel.sendMessage(String.format("I'm not allowed to mute %s", target)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
ctx.getGuild().mute(target, true).reason("Muted for Among Us.").queue();
});
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.
the class IMusicCommand method isInvalidChannelStateForCommand.
static boolean isInvalidChannelStateForCommand(CommandContext ctx, TextChannel channel, Integer deleteDelay) {
final Member self = ctx.getSelfMember();
final GuildVoiceState selfVoiceState = self.getVoiceState();
if (!selfVoiceState.inVoiceChannel()) {
channel.sendMessage("I need to be in a voice channel for this to work").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return true;
}
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
if (!memberVoiceState.inVoiceChannel()) {
channel.sendMessage("You need to be in a voice channel for this command to work").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return true;
}
if (!memberVoiceState.getChannel().equals(selfVoiceState.getChannel())) {
channel.sendMessage("You need to be in the same voice channel as me for this to work").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return true;
}
return false;
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project Bean by Xirado.
the class InteractionCommandHandler method handleSlashCommand.
public void handleSlashCommand(@NotNull SlashCommandInteractionEvent event, @Nullable Member member) {
Runnable r = () -> {
try {
if (!event.isFromGuild())
return;
Guild guild = event.getGuild();
SlashCommand command = null;
long guildId = event.getGuild().getIdLong();
if (registeredGuildCommands.containsKey(guildId)) {
List<SlashCommand> guildCommands = registeredGuildCommands.get(guildId).stream().filter(cmd -> cmd instanceof SlashCommand).map(cmd -> (SlashCommand) cmd).toList();
SlashCommand guildCommand = guildCommands.stream().filter(cmd -> cmd.getCommandName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
if (guildCommand != null)
command = guildCommand;
}
if (command == null) {
SlashCommand globalCommand = getRegisteredSlashCommands().stream().filter(cmd -> cmd.getCommandName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
if (globalCommand != null)
command = globalCommand;
}
if (command != null) {
SlashCommandContext ctx = new SlashCommandContext(event);
List<Permission> neededPermissions = command.getRequiredUserPermissions();
List<Permission> neededBotPermissions = command.getRequiredBotPermissions();
if (neededPermissions != null && !member.hasPermission((GuildChannel) event.getChannel(), neededPermissions)) {
event.reply(LocaleLoader.ofGuild(guild).get("general.no_perms", String.class)).queue();
return;
}
if (neededBotPermissions != null && !event.getGuild().getSelfMember().hasPermission((GuildChannel) event.getChannel(), neededBotPermissions)) {
event.reply(LocaleLoader.ofGuild(guild).get("general.no_bot_perms1", String.class)).queue();
return;
}
if (command.getCommandFlags().contains(CommandFlag.DJ_ONLY)) {
if (!ctx.getGuildData().isDJ(member)) {
event.replyEmbeds(EmbedUtil.errorEmbed("You need to be a DJ to do this!")).queue();
return;
}
}
if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_VC)) {
GuildVoiceState guildVoiceState = member.getVoiceState();
if (guildVoiceState == null || !guildVoiceState.inAudioChannel()) {
event.replyEmbeds(EmbedUtil.errorEmbed("You are not connected to a voice-channel!")).queue();
return;
}
}
if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_SAME_VC)) {
GuildVoiceState voiceState = member.getVoiceState();
AudioManager manager = event.getGuild().getAudioManager();
if (manager.isConnected()) {
if (!manager.getConnectedChannel().equals(voiceState.getChannel())) {
event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in " + manager.getConnectedChannel().getAsMention() + "to do this!")).setEphemeral(true).queue();
return;
}
}
}
if (command.getCommandFlags().contains(CommandFlag.REQUIRES_LAVALINK_NODE)) {
if (!ctx.isLavalinkNodeAvailable()) {
event.replyEmbeds(EmbedUtil.errorEmbed("There are currently no voice nodes available!\nIf the issue persists, please leave a message on our support server!")).addActionRow(Util.getSupportButton()).queue();
return;
}
}
command.executeCommand(event, ctx);
Metrics.COMMANDS.labels("success").inc();
}
} catch (Exception e) {
Metrics.COMMANDS.labels("failed").inc();
LinkedDataObject translation = event.getGuild() == null ? LocaleLoader.getForLanguage("en_US") : LocaleLoader.ofGuild(event.getGuild());
if (event.isAcknowledged())
event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
}, ex -> {
});
else
event.replyEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
}, ex -> {
});
LOGGER.error("Could not execute slash-command", e);
StringBuilder path = new StringBuilder("/" + event.getCommandPath().replace("/", " "));
for (OptionMapping option : event.getOptions()) {
path.append(" *").append(option.getName()).append("* : ").append("`").append(option.getAsString()).append("`");
}
EmbedBuilder builder = new EmbedBuilder().setTitle("An error occurred while executing a slash-command!").addField("Guild", event.getGuild() == null ? "None (Direct message)" : event.getGuild().getIdLong() + " (" + event.getGuild().getName() + ")", true).addField("Channel", event.getGuild() == null ? "None (Direct message)" : event.getChannel().getName(), true).addField("User", event.getUser().getAsMention() + " (" + event.getUser().getAsTag() + ")", true).addField("Command", path.toString(), false).setColor(EmbedUtil.ERROR_COLOR);
event.getJDA().openPrivateChannelById(Bean.OWNER_ID).flatMap(c -> c.sendMessageEmbeds(builder.build()).content("```fix\n" + ExceptionUtils.getStackTrace(e) + "\n```")).queue();
}
};
Bean.getInstance().getCommandExecutor().execute(r);
}
Aggregations