use of net.dv8tion.jda.api.managers.AudioManager in project PorkBot by DaMatrix.
the class ServerAudioManager method connect.
public synchronized boolean connect(VoiceChannel dstChannel, boolean errorMsg) {
AudioManager manager = this.guild.getAudioManager();
if (!manager.isConnected() && !manager.isAttemptingToConnect()) {
if (!dstChannel.getGuild().getMember(dstChannel.getJDA().getSelfUser()).hasPermission(dstChannel, Permission.VOICE_CONNECT)) {
if (errorMsg && this.lastAccessedFrom != null) {
this.lastAccessedFrom.sendMessage("No permission to join channel `" + dstChannel.getName() + '`').queue();
}
return false;
} else if (!dstChannel.getGuild().getMember(dstChannel.getJDA().getSelfUser()).hasPermission(dstChannel, Permission.VOICE_SPEAK)) {
if (errorMsg && this.lastAccessedFrom != null) {
this.lastAccessedFrom.sendMessage("No permission to speak in channel `" + dstChannel.getName() + '`').queue();
}
return false;
}
manager.setSelfDeafened(true);
manager.setSelfMuted(false);
manager.openAudioConnection(dstChannel);
}
return true;
}
use of net.dv8tion.jda.api.managers.AudioManager in project PorkBot by DaMatrix.
the class ServerAudioManager method connectedChannel.
public VoiceChannel connectedChannel() {
AudioManager manager = this.guild.getAudioManager();
VoiceChannel channel = manager.getQueuedAudioConnection();
return channel == null ? manager.getConnectedChannel() : channel;
}
use of net.dv8tion.jda.api.managers.AudioManager in project JDA by DV8FromTheWorld.
the class GuildImpl method getAudioManager.
@Nonnull
@Override
public AudioManager getAudioManager() {
if (!getJDA().isIntent(GatewayIntent.GUILD_VOICE_STATES))
throw new IllegalStateException("Cannot use audio features with disabled GUILD_VOICE_STATES intent!");
final AbstractCacheView<AudioManager> managerMap = getJDA().getAudioManagersView();
AudioManager mng = managerMap.get(id);
if (mng == null) {
// No previous manager found -> create one
try (UnlockHook hook = managerMap.writeLock()) {
GuildImpl cachedGuild = (GuildImpl) getJDA().getGuildById(id);
if (cachedGuild == null)
throw new IllegalStateException("Cannot get an AudioManager instance on an uncached Guild");
mng = managerMap.get(id);
if (mng == null) {
mng = new AudioManagerImpl(cachedGuild);
managerMap.getMap().put(id, mng);
}
}
}
return mng;
}
use of net.dv8tion.jda.api.managers.AudioManager in project JDA by DV8FromTheWorld.
the class WebSocketSendingThread method handleAudioRequest.
private void handleAudioRequest(ConnectionRequest audioRequest) {
long channelId = audioRequest.getChannelId();
long guildId = audioRequest.getGuildIdLong();
Guild guild = api.getGuildById(guildId);
if (guild == null) {
LOG.debug("Discarding voice request due to null guild {}", guildId);
// race condition on guild delete, avoid NPE on DISCONNECT requests
queuedAudioConnections.remove(guildId);
return;
}
ConnectionStage stage = audioRequest.getStage();
AudioManager audioManager = guild.getAudioManager();
DataObject packet;
switch(stage) {
case RECONNECT:
case DISCONNECT:
packet = newVoiceClose(guildId);
break;
default:
case CONNECT:
packet = newVoiceOpen(audioManager, channelId, guild.getIdLong());
}
LOG.debug("Sending voice request {}", packet);
if (send(packet)) {
// If we didn't get RateLimited, Next request attempt will be 10 seconds from now
// we remove it in VoiceStateUpdateHandler once we hear that it has updated our status
// in 10 seconds we will attempt again in case we did not receive an update
audioRequest.setNextAttemptEpoch(System.currentTimeMillis() + 10000);
// If we are already in the correct state according to voice state
// we will not receive a VOICE_STATE_UPDATE that would remove it
// thus we update it here
final GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
client.updateAudioConnection0(guild.getIdLong(), voiceState.getChannel());
}
}
use of net.dv8tion.jda.api.managers.AudioManager in project discord-bot-reddit-java by Glaxier0.
the class LeaveCommand method execute.
@Override
public void execute(SlashCommandInteractionEvent event) {
GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
GuildVoiceState userVoiceState = event.getMember().getVoiceState();
if (utils.channelControl(botVoiceState, userVoiceState)) {
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
AudioManager audioManager = event.getGuild().getAudioManager();
musicManager.scheduler.player.stopTrack();
musicManager.scheduler.queue.clear();
audioManager.closeAudioConnection();
event.replyEmbeds(new EmbedBuilder().setDescription("Bye.").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());
}
Aggregations