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());
}
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();
}
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());
}
}
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());
}
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());
}
Aggregations