Java Code Examples for net.dv8tion.jda.api.JDA#getGuildChannelById()

The following examples show how to use net.dv8tion.jda.api.JDA#getGuildChannelById() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermOverrideManagerImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
private SnowflakeReference<PermissionOverride> setupReferent(PermissionOverride override)
{
    JDA api = override.getJDA();
    GuildChannel channel = override.getChannel();
    long channelId = channel.getIdLong();
    ChannelType type = channel.getType();
    boolean role = override.isRoleOverride();
    return new SnowflakeReference<>(override, (holderId) -> {
        GuildChannel targetChannel = api.getGuildChannelById(type, channelId);
        if (targetChannel == null)
            return null;
        Guild guild = targetChannel.getGuild();
        IPermissionHolder holder;
        if (role)
            holder = guild.getRoleById(holderId);
        else
            holder = guild.getMemberById(holderId);
        if (holder == null)
            return null;
        return targetChannel.getPermissionOverride(holder);
    });
}
 
Example 2
Source File: ChannelManagerImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ChannelManager instance
 *
 * @param channel
 *        {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} that should be modified
 *        <br>Either {@link net.dv8tion.jda.api.entities.VoiceChannel Voice}- or {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}
 */
public ChannelManagerImpl(GuildChannel channel)
{
    super(channel.getJDA(),
          Route.Channels.MODIFY_CHANNEL.compile(channel.getId()));
    JDA jda = channel.getJDA();
    ChannelType type = channel.getType();
    this.channel = new SnowflakeReference<>(channel, (channelId) -> jda.getGuildChannelById(type, channelId));
    if (isPermissionChecksEnabled())
        checkPermissions();
    this.overridesAdd = new TLongObjectHashMap<>();
    this.overridesRem = new TLongHashSet();
}
 
Example 3
Source File: InsufficientPermissionException.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * The {@link net.dv8tion.jda.api.entities.GuildChannel} instance for the {@link #getChannelId() channel id}.
 *
 * @param  api
 *         The shard to perform the lookup in
 *
 * @throws java.lang.IllegalArgumentException
 *         If the provided JDA instance is null
 *
 * @since  4.0.0
 *
 * @return The GuildChannel instance or null
 */
@Nullable
public GuildChannel getChannel(@Nonnull JDA api)
{
    Checks.notNull(api, "JDA");
    return api.getGuildChannelById(channelType, channelId);
}
 
Example 4
Source File: ShardManager.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Get {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} for the provided ID.
 * <br>This checks if any of the channel types in this guild have the provided ID and returns the first match.
 *
 * <br>To get more specific channel types you can use one of the following:
 * <ul>
 *     <li>{@link #getTextChannelById(long)}</li>
 *     <li>{@link #getVoiceChannelById(long)}</li>
 *     <li>{@link #getStoreChannelById(long)}</li>
 *     <li>{@link #getCategoryById(long)}</li>
 * </ul>
 *
 * @param  id
 *         The ID of the channel
 *
 * @return The GuildChannel or null
 */
@Nullable
default GuildChannel getGuildChannelById(long id)
{
    GuildChannel channel;
    for (JDA shard : getShards())
    {
        channel = shard.getGuildChannelById(id);
        if (channel != null)
            return channel;
    }

    return null;
}
 
Example 5
Source File: ShardManager.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Get {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} for the provided ID.
 *
 * <br>This is meant for systems that use a dynamic {@link net.dv8tion.jda.api.entities.ChannelType} and can
 * profit from a simple function to get the channel instance.
 * To get more specific channel types you can use one of the following:
 * <ul>
 *     <li>{@link #getTextChannelById(long)}</li>
 *     <li>{@link #getVoiceChannelById(long)}</li>
 *     <li>{@link #getStoreChannelById(long)}</li>
 *     <li>{@link #getCategoryById(long)}</li>
 * </ul>
 *
 * @param  type
 *         The {@link net.dv8tion.jda.api.entities.ChannelType}
 * @param  id
 *         The ID of the channel
 *
 * @throws java.lang.IllegalArgumentException
 *         If the provided {@link net.dv8tion.jda.api.entities.ChannelType} is null
 *
 * @return The GuildChannel or null
 */
@Nullable
default GuildChannel getGuildChannelById(@Nonnull ChannelType type, long id)
{
    Checks.notNull(type, "ChannelType");
    GuildChannel channel;
    for (JDA shard : getShards())
    {
        channel = shard.getGuildChannelById(type, id);
        if (channel != null)
            return channel;
    }

    return null;
}