Search in sources :

Example 6 with GuildVoiceState

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();
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) AudioChannel(net.dv8tion.jda.api.entities.AudioChannel) Permission(net.dv8tion.jda.api.Permission) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) Route(net.dv8tion.jda.internal.requests.Route) RestActionImpl(net.dv8tion.jda.internal.requests.RestActionImpl) Commands(net.dv8tion.jda.api.interactions.commands.build.Commands) CommandFlag(at.xirado.bean.command.CommandFlag) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) SlashCommand(at.xirado.bean.command.SlashCommand) DataObject(net.dv8tion.jda.api.utils.data.DataObject) NotNull(org.jetbrains.annotations.NotNull) EmbedUtil(at.xirado.bean.misc.EmbedUtil) RestAction(net.dv8tion.jda.api.requests.RestAction) AudioChannel(net.dv8tion.jda.api.entities.AudioChannel) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState)

Example 7 with GuildVoiceState

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();
}
Also used : TrackInfo(at.xirado.bean.misc.objects.TrackInfo) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer)

Example 8 with GuildVoiceState

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);
}
Also used : PermissionException(net.dv8tion.jda.api.exceptions.PermissionException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) AudioHandler(com.jagrosh.jmusicbot.audio.AudioHandler) Settings(com.jagrosh.jmusicbot.settings.Settings)

Example 9 with GuildVoiceState

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;
}
Also used : AudioPlayerSendHandler(io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler) AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Example 10 with GuildVoiceState

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();
    }
}
Also used : AudioPlayerSendHandler(io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler) AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

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