use of net.dv8tion.jda.api.entities.GuildVoiceState in project discord-bot-reddit-java by Glaxier0.
the class SkipCommand method execute.
@Override
public void execute(SlashCommandInteractionEvent event) {
GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
GuildVoiceState userVoiceState = event.getMember().getVoiceState();
if (utils.channelControl(botVoiceState, userVoiceState)) {
PlayerManager.getInstance().getMusicManager(event).scheduler.nextTrack();
event.replyEmbeds(new EmbedBuilder().setDescription("Song skipped").setColor(Color.GREEN).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 SwapCommand 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);
List<AudioTrack> trackList = new ArrayList<>(musicManager.scheduler.queue);
if (trackList.size() > 1) {
int first = event.getOption("songnum1").getAsInt() - 1;
int second = event.getOption("songnum2").getAsInt() - 1;
try {
AudioTrack temp = trackList.get(first);
trackList.set(first, trackList.get(second));
trackList.set(second, temp);
} catch (Exception e) {
event.replyEmbeds(new EmbedBuilder().setDescription("Please enter a valid queue ids for both of the songs.").setColor(Color.RED).build()).queue();
return;
}
musicManager.scheduler.queue.clear();
for (AudioTrack track : trackList) {
musicManager.scheduler.queue(track);
}
event.replyEmbeds(new EmbedBuilder().setDescription("Successfully swapped order of two songs").setColor(Color.GREEN).build()).queue();
} else if (trackList.size() == 1) {
event.replyEmbeds(new EmbedBuilder().setDescription("There is only one song in queue.").setColor(Color.RED).build()).queue();
} else {
event.replyEmbeds(new EmbedBuilder().setDescription("Queue is empty.").setColor(Color.RED).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 toby-bot by ml404.
the class SetVolumeCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
final Member self = ctx.getSelfMember();
final GuildVoiceState selfVoiceState = self.getVoiceState();
if (!requestingUserDto.hasMusicPermission()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
if (ctx.getArgs().isEmpty()) {
channel.sendMessage(getHelp(prefix)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
final Member member = ctx.getMember();
setNewVolume(ctx, prefix, channel, member, deleteDelay);
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.
the class JoinCommand method doJoinChannelValidation.
private GuildVoiceState doJoinChannelValidation(CommandContext ctx, TextChannel channel, Integer deleteDelay) {
final Member self = ctx.getSelfMember();
final GuildVoiceState selfVoiceState = self.getVoiceState();
if (selfVoiceState.inVoiceChannel()) {
channel.sendMessage("I'm already in a voice channel").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return null;
}
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
if (!memberVoiceState.inVoiceChannel()) {
channel.sendMessage("You need to be in a voice channel for this command to work").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return null;
}
return memberVoiceState;
}
use of net.dv8tion.jda.api.entities.GuildVoiceState in project toby-bot by ml404.
the class JoinCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
final Member self = ctx.getSelfMember();
if (!requestingUserDto.hasMusicPermission()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
final GuildVoiceState memberVoiceState = doJoinChannelValidation(ctx, channel, deleteDelay);
if (memberVoiceState == null)
return;
final AudioManager audioManager = ctx.getGuild().getAudioManager();
final VoiceChannel memberChannel = memberVoiceState.getChannel();
if (self.hasPermission(Permission.VOICE_CONNECT)) {
audioManager.openAudioConnection(memberChannel);
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
ConfigDto databaseConfig = configService.getConfigByName(volumePropertyName, ctx.getGuild().getId());
int defaultVolume = databaseConfig != null ? Integer.parseInt(databaseConfig.getValue()) : 100;
PlayerManager.getInstance().getMusicManager(ctx.getGuild()).getAudioPlayer().setVolume(defaultVolume);
channel.sendMessageFormat("Connecting to `\uD83D\uDD0A %s` with volume '%s'", memberChannel.getName(), defaultVolume).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
}
Aggregations