本文整理汇总了Java中net.dv8tion.jda.core.managers.AudioManager.openAudioConnection方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.openAudioConnection方法的具体用法?Java AudioManager.openAudioConnection怎么用?Java AudioManager.openAudioConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.managers.AudioManager
的用法示例。
在下文中一共展示了AudioManager.openAudioConnection方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: joinChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public void joinChannel(VoiceChannel targetChannel) throws MessagingException {
if (targetChannel == null) {
throw new MessagingException(I18n.get(getGuild()).getString("playerUserNotInChannel"));
}
if (!PermissionUtil.checkPermission(targetChannel, targetChannel.getGuild().getSelfMember(), Permission.VOICE_CONNECT)
&& !targetChannel.getMembers().contains(getGuild().getSelfMember())) {
throw new MessagingException(I18n.get(getGuild()).getString("playerJoinConnectDenied"));
}
if (!PermissionUtil.checkPermission(targetChannel, targetChannel.getGuild().getSelfMember(), Permission.VOICE_SPEAK)) {
throw new MessagingException(I18n.get(getGuild()).getString("playerJoinSpeakDenied"));
}
AudioManager manager = getGuild().getAudioManager();
manager.openAudioConnection(targetChannel);
log.info("Connected to voice channel " + targetChannel);
}
示例2: connectToVoiceChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
@CheckReturnValue
private static VoiceConnectStatus connectToVoiceChannel(Message message, VoiceChannel channel, AudioManager audioManager) {
List<Permission> permissions = message.getGuild().getMember(message.getJDA().getSelfUser()).getPermissions(channel);
if (!permissions.contains(Permission.VOICE_CONNECT)) {
return VoiceConnectStatus.MISSING_PERMISSIONS;
}
if (channel.getUserLimit() > 0 && !permissions.contains(Permission.VOICE_MOVE_OTHERS) && channel.getUserLimit() <= channel.getMembers().size()) {
return VoiceConnectStatus.USER_LIMIT;
}
try {
audioManager.openAudioConnection(channel);
} catch (Exception ex) {
return VoiceConnectStatus.USER_LIMIT;
}
return VoiceConnectStatus.CONNECTED;
}
示例3: open
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public void open(VoiceChannel channel) {
if (channel == null) {
return;
}
AudioManager manager = guild.getAudioManager();
if (manager.isConnected()) {
return;
}
manager.openAudioConnection(channel);
manager.setAutoReconnect(true);
manager.setSelfMuted(true);
}
示例4: joinChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
private boolean joinChannel(VoiceChannel channel, Guild guild)
{
log.info("Attempt to join channel: <" + channel.getName() + ">");
// Gets the audio manager, and opens an audio connection (Connects to the voice channel)
AudioManager manager = guild.getAudioManager();
if (manager.isConnected() || manager.isAttemptingToConnect())
{
manager.closeAudioConnection();
manager.openAudioConnection(channel);
}
else
manager.openAudioConnection(channel);
// Waits for the connection to occur.
int iterations = 0;
while (!manager.isConnected())
{
try
{
if (iterations >= MAX_ATTEMPTS)
break;
Thread.sleep(100);
iterations++;
}
catch (InterruptedException e)
{
log.warn("Interrupted while attempting to connect to voice channel.");
return false;
}
}
log.info("Successfully joined channel: <" + channel.getName() + ">");
return true;
}
示例5: connectToVoiceChat
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public int connectToVoiceChat(AudioManager manager, Member member) {
int res = 0;
if (member.getVoiceState().inVoiceChannel()) {
manager.openAudioConnection(member.getVoiceState().getChannel());
getGuildAudioPlayer(manager.getGuild()).scheduler.changeVolume(20);
res = 1;
}
return res;
}
示例6: connectToVoiceChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
/**
* Connect the bot to a voice channel
* @param audioManager The AudioManager of a guild
* @param voiceChannel The voice channel to connect in.
*/
private static void connectToVoiceChannel(AudioManager audioManager, VoiceChannel voiceChannel) {
audioManager.setSelfMuted(false);
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
audioManager.openAudioConnection(voiceChannel);
}
}
示例7: createPlayer
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public GuildMusicPlayer createPlayer(long guildId, long textChannelId, long voiceChannelId) {
GuildMusicPlayer gmp = getPlayer(guildId);
if(gmp == null) {
synchronized(this) {
gmp = new GuildMusicPlayer(guildId, textChannelId, voiceChannelId);
//gmp.link.connect(jda.getGuildById(guildId).getVoiceChannelById(voiceChannelId));
AudioManager manager = jda.getGuildById(guildId).getAudioManager();
manager.setSendingHandler(gmp);
manager.openAudioConnection(jda.getGuildById(guildId).getVoiceChannelById(voiceChannelId));
players.put(guildId, gmp);
}
}
return gmp;
}
示例8: connectToFirstVoiceChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
private static void connectToFirstVoiceChannel(AudioManager audioManager) {
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
for (VoiceChannel voiceChannel : audioManager.getGuild().getVoiceChannels()) {
audioManager.openAudioConnection(voiceChannel);
break;
}
}
}
示例9: connectToUsersVoiceChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
private void connectToUsersVoiceChannel(CommandContext context) {
AudioManager audioManager = context.getGuild().getAudioManager();
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
Optional<VoiceChannel> voiceChannel = context.getGuild().getVoiceChannels().stream().filter(c -> c.getMembers().contains(context.getMember())).findFirst();
if (!voiceChannel.isPresent()) {
context.getTextChannel().sendMessage(KekBot.respond(context, Action.GET_IN_VOICE_CHANNEL)).queue();
} else {
audioManager.openAudioConnection(voiceChannel.get());
if (!isMeme(context.getGuild())) {
context.getTextChannel().sendMessage(context.getAuthor().getAsMention() + " is now hosting a music session in: `" + voiceChannel.get().getName() + "`" + KekBot.replacePrefix(context.getGuild(), ", use {p}music to get the list of all music commands.")).queue();
musicManagers.get(Long.parseLong(context.getGuild().getId())).scheduler.currentPlayer = context.getAuthor();
}
}
}
}
示例10: joinVoiceChannel
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
private void joinVoiceChannel(TextChannel channel) {
Guild guild = channel.getGuild();
AudioManager am = guild.getAudioManager();
try {
am.openAudioConnection(guild.getVoiceChannelsByName("Music", true).get(0));
} catch(Exception e) {
channel.sendMessage("You need to create a voice channel named `Music`!").queue();
}
}
示例11: execute
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public void execute(GuildMessageReceivedEvent e, String query) {
final Permissions permissions = new Permissions();
if (query.length() == 0) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("No Search Query Specified")
.setDescription("Specify a term to search YouTube for")
.build()
).queue();
return;
}
final AudioManager manager = e.getGuild().getAudioManager();
final AudioHandler player = JukeBot.getPlayer(manager);
if (!permissions.checkVoiceChannel(e.getMember())) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("No Mutual VoiceChannel")
.setDescription("Join my VoiceChannel to use this command.")
.build()
).queue();
return;
}
if (!manager.isAttemptingToConnect() && !manager.isConnected()) {
ConnectionError connectionStatus = permissions.canConnect(e.getMember().getVoiceState().getChannel());
if (null != connectionStatus) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle(connectionStatus.title)
.setDescription(connectionStatus.description)
.build()
).queue();
return;
}
manager.openAudioConnection(e.getMember().getVoiceState().getChannel());
player.setChannel(e.getChannel());
}
JukeBot.playerManager.loadItem("ytsearch:" + query, new SongResultHandler(e, player, true));
}
示例12: execute
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public void execute(GuildMessageReceivedEvent e, String query) {
if (query.length() == 0) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("Specify something")
.setDescription("YouTube: Search Term/URL\nSoundCloud: URL")
.build()
).queue();
return;
}
final AudioManager manager = e.getGuild().getAudioManager();
final AudioHandler player = JukeBot.getPlayer(manager);
if (!permissions.checkVoiceChannel(e.getMember())) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("No Mutual VoiceChannel")
.setDescription("Join my VoiceChannel to use this command.")
.build()
).queue();
return;
}
if (!manager.isAttemptingToConnect() && !manager.isConnected()) {
ConnectionError connectionStatus = permissions.canConnect(e.getMember().getVoiceState().getChannel());
if (null != connectionStatus) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle(connectionStatus.title)
.setDescription(connectionStatus.description)
.build()
).queue();
return;
}
manager.openAudioConnection(e.getMember().getVoiceState().getChannel());
player.setChannel(e.getChannel());
}
final String userQuery = query.replaceAll("[<>]", "");
if (userQuery.startsWith("http"))
JukeBot.playerManager.loadItem(userQuery, new SongResultHandler(e, player, false));
else
JukeBot.playerManager.loadItem( "ytsearch:" + userQuery, new SongResultHandler(e, player, false));
}
示例13: execute
import net.dv8tion.jda.core.managers.AudioManager; //导入方法依赖的package包/类
public void execute(GuildMessageReceivedEvent e, String query) {
if (query.length() == 0) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("No Search Query Specified")
.setDescription("Specify a term to search SoundCloud for")
.build()
).queue();
return;
}
final AudioManager manager = e.getGuild().getAudioManager();
final AudioHandler player = JukeBot.getPlayer(manager);
if (!permissions.checkVoiceChannel(e.getMember())) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("No Mutual VoiceChannel")
.setDescription("Join my VoiceChannel to use this command.")
.build()
).queue();
return;
}
if (!manager.isAttemptingToConnect() && !manager.isConnected()) {
ConnectionError connectionStatus = permissions.canConnect(e.getMember().getVoiceState().getChannel());
if (null != connectionStatus) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle(connectionStatus.title)
.setDescription(connectionStatus.description)
.build()
).queue();
return;
}
manager.openAudioConnection(e.getMember().getVoiceState().getChannel());
player.setChannel(e.getChannel());
}
JukeBot.playerManager.loadItem("scsearch:" + query, new SongResultHandler(e, player, false));
}