use of net.dv8tion.jda.api.managers.AudioManager in project Wylx by Wylx-Bot.
the class VoiceChannelProcessing method checkVoiceChannel.
private void checkVoiceChannel(long guildID) {
GuildMusicManager guildMusicManager = WylxPlayerManager.getInstance().getGuildManager(guildID);
AudioManager manager = Wylx.getInstance().getGuildAudioManager(guildID);
AudioChannel channel = manager.getConnectedChannel();
if (channel == null) {
guildMusicManager.stop();
return;
}
// Leave if we are the only user left
if (manager.isConnected() && channel.getMembers().size() == 1) {
logger.debug("Leaving {} due to inactivity", guildID);
guildMusicManager.stop();
}
}
use of net.dv8tion.jda.api.managers.AudioManager in project ascent_bot by FeroniK.
the class TrackScheduler method onTrackEnd.
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
if (endReason.mayStartNext) {
if (this.isRepeating) {
this.player.startTrack(track.makeClone(), false);
return;
}
if (this.queue.isEmpty() && currentGuild != null) {
AudioManager audioManager = currentGuild.getAudioManager();
audioManager.closeAudioConnection();
return;
}
nextTrack();
}
}
use of net.dv8tion.jda.api.managers.AudioManager in project ascent_bot by FeroniK.
the class Leave method handle.
@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
musicManager.scheduler.isRepeating = false;
musicManager.scheduler.queue.clear();
musicManager.scheduler.player.startTrack(null, false);
AudioManager audioManager = ctx.getGuild().getAudioManager();
audioManager.closeAudioConnection();
String desc = "Disconnected from " + memberVoiceState.getChannel().getAsMention();
EmbedBuilder builder = Embeds.createBuilder("Disconnected", desc, "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of net.dv8tion.jda.api.managers.AudioManager in project ascent_bot by FeroniK.
the class MusicCommand method handleMusicCommands.
@SuppressWarnings("ConstantConditions")
public static void handleMusicCommands(CommandContext ctx, ICommand cmd) {
final TextChannel channel = ctx.getChannel();
final Member selfMember = ctx.getSelfMember();
GuildVoiceState selfVoiceState = selfMember.getVoiceState();
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
if (!memberVoiceState.inVoiceChannel()) {
channel.sendMessageEmbeds(Embeds.notConnectedToVcEmbed(member).build()).queue();
return;
}
if (cmd.isDjNeeded()) {
Role dj = member.getRoles().stream().filter((role) -> role.getName().equalsIgnoreCase("DJ")).findFirst().orElse(null);
boolean canInteract = ctx.getGuild().getSelfMember().canInteract(member);
List<Member> collect = memberVoiceState.getChannel().getMembers().stream().filter((mem) -> !mem.getUser().isBot() && mem != member).collect(Collectors.toList());
if (dj == null && canInteract && !collect.isEmpty()) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "You do not have the DJ Role in the server", null, null, null).build()).queue();
return;
}
}
AudioManager audioManager = ctx.getGuild().getAudioManager();
audioManager.setSelfDeafened(true);
if (!selfVoiceState.inVoiceChannel()) {
if (cmd.getName().equalsIgnoreCase("leave")) {
EmbedBuilder builder = Embeds.alreadyConnectedToVcEmbed(member);
builder.setDescription("I am not connected to a voice channel");
channel.sendMessageEmbeds(builder.build()).queue();
return;
} else // check if its a auto join command
if (cmd.getName().equalsIgnoreCase("join") || cmd.getName().equalsIgnoreCase("play") || cmd.getName().equalsIgnoreCase("search") || cmd.getName().equalsIgnoreCase("scplay") || cmd.getName().equalsIgnoreCase("spotify")) {
if (!selfMember.hasPermission(Permission.VOICE_CONNECT)) {
channel.sendMessageEmbeds(Embeds.notEnoughPermsEmbed(member).build()).queue();
return;
}
final VoiceChannel memberChannel = memberVoiceState.getChannel();
audioManager.openAudioConnection(memberChannel);
cmd.handle(ctx);
} else {
EmbedBuilder builder = Embeds.notInSameVcEmbed(member);
builder.setDescription("Bot must be present in a VoiceChannel to use this Command");
channel.sendMessageEmbeds(builder.build()).queue();
}
return;
}
if (!memberVoiceState.getChannel().getId().equals(selfVoiceState.getChannel().getId())) {
channel.sendMessageEmbeds(Embeds.notInSameVcEmbed(member).setDescription("Already connected to a different channel").build()).queue();
return;
} else {
if (cmd.getName().equalsIgnoreCase("join")) {
channel.sendMessageEmbeds(Embeds.alreadyConnectedToVcEmbed(member).build()).queue();
return;
}
}
cmd.handle(ctx);
}
use of net.dv8tion.jda.api.managers.AudioManager in project radio by toadless.
the class GuildMusicManager method join.
public void join(@NotNull VoiceChannel channel) {
AudioManager manager = channel.getGuild().getAudioManager();
manager.openAudioConnection(channel);
player.setVolume(volume);
}
Aggregations