Search in sources :

Example 1 with VoiceChannel

use of discord4j.core.object.entity.VoiceChannel in project lavaplayer by sedmelluq.

the class Main method attachToFirstVoiceChannel.

private static void attachToFirstVoiceChannel(Guild guild, D4jAudioProvider provider) {
    VoiceChannel voiceChannel = guild.getChannels().ofType(VoiceChannel.class).blockFirst();
    boolean inVoiceChannel = // Check if any VoiceState for this guild relates to bot
    guild.getVoiceStates().any(voiceState -> guild.getClient().getSelfId().map(voiceState.getUserId()::equals).orElse(false)).block();
    if (!inVoiceChannel) {
        voiceChannel.join(spec -> spec.setProvider(provider)).block();
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) Guild(discord4j.core.object.entity.Guild) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) Logger(org.slf4j.Logger) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) VoiceChannel(discord4j.core.object.entity.VoiceChannel) EventDispatcher(discord4j.core.event.EventDispatcher) DiscordClientBuilder(discord4j.core.DiscordClientBuilder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) DiscordClient(discord4j.core.DiscordClient) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) Message(discord4j.core.object.entity.Message) Map(java.util.Map) MessageChannel(discord4j.core.object.entity.MessageChannel) AudioSourceManagers(com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) TextChannel(discord4j.core.object.entity.TextChannel) VoiceChannel(discord4j.core.object.entity.VoiceChannel)

Aggregations

AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)1 AudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)1 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)1 AudioSourceManagers (com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 DiscordClient (discord4j.core.DiscordClient)1 DiscordClientBuilder (discord4j.core.DiscordClientBuilder)1 EventDispatcher (discord4j.core.event.EventDispatcher)1 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)1 Guild (discord4j.core.object.entity.Guild)1 Message (discord4j.core.object.entity.Message)1 MessageChannel (discord4j.core.object.entity.MessageChannel)1 TextChannel (discord4j.core.object.entity.TextChannel)1 VoiceChannel (discord4j.core.object.entity.VoiceChannel)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1