本文整理汇总了Java中net.dv8tion.jda.core.entities.VoiceChannel类的典型用法代码示例。如果您正苦于以下问题:Java VoiceChannel类的具体用法?Java VoiceChannel怎么用?Java VoiceChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VoiceChannel类属于net.dv8tion.jda.core.entities包,在下文中一共展示了VoiceChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
private void open(CMessage message, String[] args) {
CGuild guild = charrizard.getCGuildManager().getGuild(message.getGuild());
if (guild == null) {
charrizard.getCGuildManager().createGuild(message.getGuild());
guild = charrizard.getCGuildManager().getGuild(message.getGuild());
}
CAudio audio = guild.getAudio();
if (audio.isConnected()) {
return;
}
VoiceChannel channel = message.getGuild().getVoiceChannels().stream().filter(voice -> voice.getMembers().stream().filter(member -> member.getUser().getId().equals(message.getAuthor().getId())).findFirst().orElse(null) != null).findFirst().orElse(null);
if (channel == null) {
return;
}
audio.open(channel);
}
示例2: createGuild
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
public void createGuild(Guild guild) {
if (guild == null) {
return;
}
if (getGuild(guild) != null) {
return;
}
CGuild cGuild = new CGuild(guild, charrizard);
for (TextChannel channel : guild.getTextChannels()) {
cGuild.createTextChannel(channel);
}
for (VoiceChannel voiceChannel : guild.getVoiceChannels()) {
cGuild.createVoiceChannel(voiceChannel);
}
guildCache.put(guild.getId(), cGuild);
}
示例3: createVoiceChannel
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
public void createVoiceChannel(VoiceChannel channel) {
if (channel == null) {
return;
}
if (getVoiceChannel(channel) != null) {
return;
}
String string = null;
if (settings.getRedis().isEnabled()) {
string = redisConnection.get("voice_" + getGuildId() + "_" + channel.getId());
}
int connections;
if (string == null) {
connections = 0;
} else {
connections = Integer.parseInt(string);
}
CVoiceChannel cVoiceChannel = new CVoiceChannel(channel, connections);
voiceChannelCache.put(channel.getId(), cVoiceChannel);
}
示例4: genChannelSearch
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
private ChannelSearch genChannelSearch(List<VoiceChannel> channels, boolean deleteChannel, CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
HashMap<String, VoiceChannel> channellist = new HashMap<>();
StringBuilder channelnames = new StringBuilder();
ArrayList<String> EMOJIS = new ArrayList<>(Arrays.asList(EMOTI));
channels.forEach(c -> {
String category;
if (c.getParent() != null)
category = c.getParent().getName();
else
category = "NONE";
channelnames.append(EMOJIS.get(0)).append(" - ").append(c.getName()).append("(`").append(c.getId()).append("`) (Category: ").append(category).append(")\n");
channellist.put(EMOJIS.get(0), c);
EMOJIS.remove(0);
});
if (channellist.isEmpty()) {
parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.error("Unknown Channel", "There is now channel with this name").build()).queue();
return null;
} else {
Message msg = parsedCommandInvocation.getMessage().getTextChannel().sendMessage(new EmbedBuilder().setColor(Colors.COLOR_SECONDARY).setDescription(channelnames.toString()).build()).complete();
channellist.keySet().forEach(e -> msg.addReaction(e).queue());
return new ChannelSearch(msg, channellist, deleteChannel);
}
}
示例5: joinVoiceChannel
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
public static void joinVoiceChannel(Member member) {
if (joined) {
return;
}
if(member == null) {
joinVoiceChannel(); // join default channel
return;
}
VoiceChannel channel = member.getVoiceState().getChannel();
// Check if member is not in a channel
if(channel == null) {
joinVoiceChannel(); // join default channel
return;
}
joinVoiceChannel(channel);
}
示例6: getGuild
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
private Guild getGuild(User user)
{
for (Guild g : bot.getGuilds())
{
for (VoiceChannel v : g.getVoiceChannels())
{
for (Member m : v.getMembers())
{
if (m.getUser().getId().equalsIgnoreCase(user.getId()))
{
return g;
}
}
}
}
return null;
}
示例7: joinChannel
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的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);
}
示例8: getHumanUsersInVC
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
/**
* @return Users who are not bots
*/
public List<Member> getHumanUsersInVC() {
VoiceChannel vc = getChannel();
if (vc == null) {
return new ArrayList<>();
}
List<Member> members = vc.getMembers();
ArrayList<Member> nonBots = new ArrayList<>();
for (Member member : members) {
if (!member.getUser().isBot()) {
nonBots.add(member);
}
}
return nonBots;
}
示例9: execute
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
if (!event.getMember().getVoiceState().inVoiceChannel()) {
event.getChannel().sendMessage("You need to be yourself in a voice channel!").queue();
return;
}
String musicChannel = plugin.getBot().getGuildSettings(event.getGuild()).getSetting(MusicPlugin.MUSIC_CHANNEL_SETTING);
VoiceChannel voiceChannel;
if (musicChannel != null) {
List<VoiceChannel> channels = event.getGuild().getVoiceChannelsByName(musicChannel, false);
if (channels.isEmpty()) {
event.getChannel().sendMessage("The channel the bot can play in doesn't exist anymore. Please ask an admin to fix it with the ``setmusicchannel`` command.").queue();
return;
}
voiceChannel = channels.get(0);
} else {
voiceChannel = event.getMember().getVoiceState().getChannel();
}
plugin.getMusicManager().loadAndPlay(event.getTextChannel(), args[0], voiceChannel);
}
示例10: execute
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
StringBuilder builder = new StringBuilder();
for(String s : args) {
builder.append(" ").append(s);
}
List<VoiceChannel> channels = event.getGuild().getVoiceChannelsByName(builder.toString().trim(), false);
if (channels.isEmpty()) {
event.getChannel().sendMessage("Channel " + builder.toString().trim() + " not found!").queue();
return;
}
plugin.getBot().getGuildSettings(event.getGuild()).setSetting(MusicPlugin.MUSIC_CHANNEL_SETTING, builder.toString().trim());
event.getChannel().sendMessage("Channel set! LegendaryBot will only play music in this channel.").queue();
}
示例11: onCommand
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
GuildMusicManager musicManager = AudioHandler.getGuildAudioPlayer(message.getGuild());
if (musicManager.getPlayer().getPlayingTrack() == null) {
return sendErrorMessage(message, "Not connected to voice, request music first with `!play`");
}
VoiceChannel channel = message.getMember().getVoiceState().getChannel();
if (channel == null) {
return sendErrorMessage(message, "You must be connected to a voice channel to use this command!");
}
VoiceConnectStatus voiceConnectStatus = AudioHandler.connectToVoiceChannel(message, true);
if (!voiceConnectStatus.isSuccess()) {
MessageFactory.makeWarning(message, voiceConnectStatus.getErrorMessage()).queue();
return false;
}
MessageFactory.makeSuccess(message, "I am now streaming music in **:channelName**")
.set("channelName", channel.getName())
.queue();
return true;
}
示例12: connectToVoiceChannel
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
@CheckReturnValue
public static VoiceConnectStatus connectToVoiceChannel(Message message, boolean moveChannelIfConnected) {
AudioManager audioManager = message.getGuild().getAudioManager();
if (!audioManager.isAttemptingToConnect()) {
VoiceChannel channel = message.getMember().getVoiceState().getChannel();
if (channel == null) {
return VoiceConnectStatus.NOT_CONNECTED;
}
if (audioManager.isConnected()) {
if (channel.getIdLong() == audioManager.getConnectedChannel().getIdLong()) {
return VoiceConnectStatus.CONNECTED;
}
if (moveChannelIfConnected) {
return connectToVoiceChannel(message, channel, audioManager);
}
return VoiceConnectStatus.CONNECTED;
}
return connectToVoiceChannel(message, channel, audioManager);
}
return VoiceConnectStatus.CONNECTED;
}
示例13: doInternal
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
@Override
protected boolean doInternal(MessageReceivedEvent message, BotContext context, String content) throws DiscordException {
if (!message.getMember().getVoiceState().inVoiceChannel()) {
messageService.onError(message.getTextChannel(), "discord.command.here.notInChannel");
return fail(message);
}
PlaybackInstance instance = playerService.getInstance(message.getGuild());
if (!instance.isActive()) {
messageService.onError(message.getTextChannel(), "discord.command.audio.notStarted");
return fail(message);
}
VoiceChannel channel = playerService.connectToChannel(instance, message.getMember());
if (channel != null) {
return ok(message, "discord.command.here.connected", channel.getName());
}
return fail(message, "discord.command.here.error");
}
示例14: getDesiredChannel
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
private VoiceChannel getDesiredChannel(Member member) {
MusicConfig musicConfig = getConfig(member.getGuild());
VoiceChannel channel = null;
if (musicConfig != null) {
if (musicConfig.isUserJoinEnabled() && member.getVoiceState().inVoiceChannel()) {
channel = member.getVoiceState().getChannel();
}
if (channel == null && musicConfig.getChannelId() != null) {
channel = discordService.getJda().getVoiceChannelById(musicConfig.getChannelId());
}
}
if (channel == null) {
channel = discordService.getDefaultMusicChannel(member.getGuild().getIdLong());
}
return channel;
}
示例15: getDefaultMusicChannel
import net.dv8tion.jda.core.entities.VoiceChannel; //导入依赖的package包/类
@Override
public VoiceChannel getDefaultMusicChannel(long guildId) {
if (!isConnected()) {
return null;
}
Guild guild = jda.getGuildById(guildId);
if (guild == null) {
return null;
}
VoiceChannel channel;
String channels = messageService.getMessage("discord.command.audio.channels");
if (StringUtils.isNotEmpty(channels)) {
for (String name : channels.split(",")) {
channel = guild.getVoiceChannelsByName(name, true).stream().findAny().orElse(null);
if (channel != null) {
return channel;
}
}
}
return guild.getVoiceChannels().stream().findAny().orElse(null);
}