Search in sources :

Example 26 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project Robertify-Bot by bombies.

the class ClearQueueSlashCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    if (!checks(event))
        return;
    sendRandomMessage(event);
    event.deferReply().queue();
    final var musicManager = RobertifyAudioManager.getInstance().getMusicManager(event.getGuild());
    final var queue = musicManager.getScheduler().queue;
    final var guild = event.getGuild();
    GeneralUtils.setCustomEmbed(event.getGuild(), "Queue");
    if (queue.isEmpty()) {
        EmbedBuilder eb = RobertifyEmbedUtils.embedMessage(guild, "There is already nothing in the queue.");
        event.getHook().sendMessageEmbeds(eb.build()).queue();
        return;
    }
    final GuildVoiceState selfVoiceState = event.getGuild().getSelfMember().getVoiceState();
    if (selfVoiceState.inVoiceChannel()) {
        if (selfVoiceState.getChannel().getMembers().size() > 2) {
            if (!musicCommandDJCheck(event)) {
                EmbedBuilder eb = RobertifyEmbedUtils.embedMessage(guild, "You need to be a DJ to use this command when there's other users in the channel!");
                event.getHook().sendMessageEmbeds(eb.build()).queue();
                return;
            }
        }
    } else {
        EmbedBuilder eb = RobertifyEmbedUtils.embedMessage(guild, "The bot isn't in a voice channel.");
        event.getHook().sendMessageEmbeds(eb.build()).queue();
        return;
    }
    queue.clear();
    new LogUtils().sendLog(guild, LogType.QUEUE_CLEAR, event.getUser().getAsMention() + " has cleared the queue");
    EmbedBuilder eb = RobertifyEmbedUtils.embedMessage(guild, "The queue was cleared!");
    event.getHook().sendMessageEmbeds(eb.build()).queue();
    GeneralUtils.setDefaultEmbed(event.getGuild());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) LogUtils(main.utils.json.logs.LogUtils)

Example 27 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project Robertify-Bot by bombies.

the class DisconnectSlashCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    if (!checks(event))
        return;
    sendRandomMessage(event);
    event.deferReply().queue();
    EmbedBuilder eb;
    final GuildVoiceState memberVoiceState = event.getMember().getVoiceState();
    Guild guild = event.getGuild();
    final GuildVoiceState selfVoiceState = guild.getSelfMember().getVoiceState();
    if (!selfVoiceState.inVoiceChannel()) {
        eb = RobertifyEmbedUtils.embedMessage(guild, "I'm already not in a voice channel!");
        event.getHook().sendMessageEmbeds(eb.build()).queue();
        return;
    }
    if (!memberVoiceState.inVoiceChannel()) {
        eb = RobertifyEmbedUtils.embedMessage(guild, "You must be in the same voice channel as me to use this command!" + "\n\nI am currently in: " + selfVoiceState.getChannel().getAsMention());
        event.getHook().sendMessageEmbeds(eb.build()).queue();
        return;
    }
    if (!memberVoiceState.getChannel().equals(selfVoiceState.getChannel())) {
        eb = RobertifyEmbedUtils.embedMessage(guild, "You must be in the same voice channel as me to use this command!" + "\n\nI am currently in: " + selfVoiceState.getChannel().getAsMention());
        event.getHook().sendMessageEmbeds(eb.build()).queue();
        return;
    }
    final var musicManager = RobertifyAudioManager.getInstance().getMusicManager(guild);
    musicManager.leave();
    new LogUtils().sendLog(guild, LogType.BOT_DISCONNECTED, event.getUser().getAsMention() + " has disconnected the bot.");
    eb = RobertifyEmbedUtils.embedMessage(guild, "Disconnected!");
    event.getHook().sendMessageEmbeds(eb.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) LogUtils(main.utils.json.logs.LogUtils) Guild(net.dv8tion.jda.api.entities.Guild)

Example 28 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState 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());
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) DataObject(net.dv8tion.jda.api.utils.data.DataObject) ConnectionStage(net.dv8tion.jda.internal.audio.ConnectionStage) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Guild(net.dv8tion.jda.api.entities.Guild)

Example 29 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState 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());
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState)

Example 30 with GuildVoiceState

use of net.dv8tion.jda.api.entities.GuildVoiceState in project discord-bot-reddit-java by Glaxier0.

the class ShuffleCommand 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();
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
        List<AudioTrack> trackList = new ArrayList<>(musicManager.scheduler.queue);
        if (trackList.size() > 1) {
            Collections.shuffle(trackList);
            musicManager.scheduler.queue.clear();
            for (AudioTrack track : trackList) {
                musicManager.scheduler.queue(track);
            }
            embedBuilder.setDescription("Queue shuffled").setColor(Color.GREEN);
        } else {
            embedBuilder.setDescription("Queue size have to be at least two.").setColor(Color.RED);
        }
        event.replyEmbeds(embedBuilder.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());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)51 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)16 Member (net.dv8tion.jda.api.entities.Member)16 LogUtils (main.utils.json.logs.LogUtils)13 AudioManager (net.dv8tion.jda.api.managers.AudioManager)12 Guild (net.dv8tion.jda.api.entities.Guild)11 TextChannel (net.dv8tion.jda.api.entities.TextChannel)9 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)9 ArrayList (java.util.ArrayList)7 Permission (net.dv8tion.jda.api.Permission)5 CommandFlag (at.xirado.bean.command.CommandFlag)4 SlashCommand (at.xirado.bean.command.SlashCommand)4 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)4 EmbedUtil (at.xirado.bean.misc.EmbedUtil)4 Message (net.dv8tion.jda.api.entities.Message)4 Bean (at.xirado.bean.Bean)3 GenericCommand (at.xirado.bean.command.GenericCommand)3 MessageContextCommand (at.xirado.bean.command.context.MessageContextCommand)3 UserContextCommand (at.xirado.bean.command.context.UserContextCommand)3 MockContextMenuCommand (at.xirado.bean.command.context.message.MockContextMenuCommand)3