use of net.dv8tion.jda.api.entities.GuildVoiceState in project Bean by Xirado.
the class VoiceGameCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
long appId = Long.parseUnsignedLong(event.getOption("application").getAsString());
boolean ephemeral = event.getOption("hide") != null && event.getOption("hide").getAsBoolean();
GuildVoiceState voiceState = event.getMember().getVoiceState();
AudioChannel audioChannel = voiceState.getChannel();
if (audioChannel == null) {
event.replyEmbeds(EmbedUtil.errorEmbed("You must be in a audio-channel to do this!")).setEphemeral(true).queue();
return;
}
event.deferReply(ephemeral).flatMap(hook -> createInvite(3600, 0, audioChannel, appId)).flatMap(url -> event.getHook().sendMessage(url)).queue();
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project Bean by Xirado.
the class ClearCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
GuildVoiceState state = event.getGuild().getSelfMember().getVoiceState();
if (state.getChannel() == null) {
event.replyEmbeds(EmbedUtil.warningEmbed("I am not connected to a voice channel!")).setEphemeral(true).queue();
return;
}
GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
if (player.getScheduler().getQueue().isEmpty()) {
event.replyEmbeds(EmbedUtil.warningEmbed("The queue is already empty!")).setEphemeral(true).queue();
return;
}
if (Util.getListeningUsers(state.getChannel()) == 1) {
player.getScheduler().getQueue().clear();
event.replyEmbeds(EmbedUtil.defaultEmbed("Cleared the queue!")).setEphemeral(true).queue();
player.forcePlayerUpdate();
return;
}
if (!ctx.getGuildData().isDJ(event.getMember())) {
boolean allowedToStop = true;
long userId = event.getUser().getIdLong();
List<AudioTrack> tracks = new ArrayList<>(player.getScheduler().getQueue());
for (AudioTrack track : tracks) {
TrackInfo trackInfo = track.getUserData(TrackInfo.class);
if (trackInfo.getRequesterIdLong() != userId) {
allowedToStop = false;
break;
}
}
if (!allowedToStop) {
event.replyEmbeds(EmbedUtil.errorEmbed("You need to be a DJ to do this!")).setEphemeral(true).queue();
return;
}
}
player.getScheduler().getQueue().clear();
event.replyEmbeds(EmbedUtil.defaultEmbed("Cleared the queue!")).setEphemeral(true).queue();
player.forcePlayerUpdate();
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project MusicBot by jagrosh.
the class MusicCommand method execute.
@Override
protected void execute(CommandEvent event) {
Settings settings = event.getClient().getSettingsFor(event.getGuild());
TextChannel tchannel = settings.getTextChannel(event.getGuild());
if (tchannel != null && !event.getTextChannel().equals(tchannel)) {
try {
event.getMessage().delete().queue();
} catch (PermissionException ignore) {
}
event.replyInDm(event.getClient().getError() + " You can only use that command in " + tchannel.getAsMention() + "!");
return;
}
// no point constantly checking for this later
bot.getPlayerManager().setUpHandler(event.getGuild());
if (bePlaying && !((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).isMusicPlaying(event.getJDA())) {
event.reply(event.getClient().getError() + " There must be music playing to use that!");
return;
}
if (beListening) {
VoiceChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel();
if (current == null)
current = settings.getVoiceChannel(event.getGuild());
GuildVoiceState userState = event.getMember().getVoiceState();
if (!userState.inVoiceChannel() || userState.isDeafened() || (current != null && !userState.getChannel().equals(current))) {
event.replyError("You must be listening in " + (current == null ? "a voice channel" : current.getAsMention()) + " to use that!");
return;
}
VoiceChannel afkChannel = userState.getGuild().getAfkChannel();
if (afkChannel != null && afkChannel.equals(userState.getChannel())) {
event.replyError("You cannot use that command in an AFK channel!");
return;
}
if (!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
try {
event.getGuild().getAudioManager().openAudioConnection(userState.getChannel());
} catch (PermissionException ex) {
event.reply(event.getClient().getError() + " I am unable to connect to " + userState.getChannel().getAsMention() + "!");
return;
}
}
}
doCommand(event);
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project FutrzakBot by Aquerr.
the class PlayCommand method execute.
@Override
public boolean execute(Member member, TextChannel textChannel, List<String> args) {
Guild guild = textChannel.getGuild();
GuildVoiceState guildVoiceState = member.getVoiceState();
VoiceChannel voiceChannel = guildVoiceState.getChannel();
if (voiceChannel == null) {
textChannel.sendMessage("Aby użyć tej komendy musisz być na kanale głosowym!").complete();
} else {
AudioManager audioManager = guild.getAudioManager();
if (audioManager.getSendingHandler() == null) {
audioManager.setSendingHandler(new AudioPlayerSendHandler(this.futrzakAudioPlayerManager.getOrCreateAudioPlayer(guild.getIdLong()).getInternalAudioPlayer()));
}
audioManager.openAudioConnection(voiceChannel);
String songName = args.get(0);
this.futrzakAudioPlayerManager.queue(guild.getIdLong(), textChannel, songName);
}
return true;
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project FutrzakBot by Aquerr.
the class SlashCommandListener method onSlashCommand.
@Override
public void onSlashCommand(SlashCommandEvent event) {
if (event.getName().equals("player")) {
if (event.getOption("song") != null) {
GuildVoiceState guildVoiceState = event.getMember().getVoiceState();
VoiceChannel voiceChannel = guildVoiceState.getChannel();
if (voiceChannel == null) {
event.reply("Aby użyć tej komendy musisz być na kanale głosowym!").queue();
}
Guild guild = event.getGuild();
AudioManager audioManager = guild.getAudioManager();
audioManager.setSendingHandler(new AudioPlayerSendHandler(this.futrzakAudioPlayerManager.getOrCreateAudioPlayer(guild.getIdLong()).getInternalAudioPlayer()));
audioManager.openAudioConnection(voiceChannel);
this.futrzakAudioPlayerManager.queue(event.getGuild().getIdLong(), event.getTextChannel(), event.getOption("song").getAsString());
}
event.reply("Futrzak Song Player").addActionRow(// Button with only a label
Button.primary("queue", "View Song Queue"), // Button with only an emoji
Button.success("next", ":track_next:")).queue();
}
}
Aggregations