/// <summary> /// Gets a channel /// </summary> /// <param name="channelId">ID of the channel</param> public static DiscordChannel GetChannel(this DiscordSocketClient client, ulong channelId) { if (client.Config.Cache) { foreach (var guild in client.GetCachedGuilds()) { foreach (var channel in guild.Channels) { if (channel.Id == channelId) { return(channel); } } } foreach (var channel in client.PrivateChannels) { if (channel.Id == channelId) { return(channel); } } throw new DiscordHttpException(client, new DiscordHttpError(DiscordError.UnknownChannel, "Channel was not found in cache")); } else { return(((DiscordClient)client).GetChannel(channelId)); } }
public static DiscordRole GetGuildRole(this DiscordSocketClient client, ulong roleId) { if (!client.Config.Cache) { throw new NotSupportedException("Caching is disabled for this client."); } foreach (var guild in client.GetCachedGuilds()) { foreach (var role in guild.Roles) { if (role.Id == roleId) { return(role); } } } throw new DiscordHttpException(new DiscordHttpError(DiscordError.UnknownRole, "Role was not found in cache")); }
public static DiscordEmoji GetGuildEmoji(this DiscordSocketClient client, ulong emojiId) { if (!client.Config.Cache) { throw new NotSupportedException("Caching is disabled for this client."); } foreach (var guild in client.GetCachedGuilds()) { foreach (var emoji in guild.Emojis) { if (emoji.Id == emojiId) { return(emoji); } } } throw new DiscordHttpException(new DiscordHttpError(DiscordError.UnknownEmoji, "Emoji was not found in cache")); }
public static async Task <DiscordChannel> GetChannelAsync(this DiscordSocketClient client, ulong channelId) { if (client.Config.Cache) { foreach (var guild in client.GetCachedGuilds()) { if (!guild.Unavailable) { lock (guild.ChannelsConcurrent.Lock) { foreach (var channel in guild.ChannelsConcurrent) { if (channel.Id == channelId) { return(channel); } } } } } lock (client.PrivateChannels.Lock) { foreach (var channel in client.PrivateChannels) { if (channel.Id == channelId) { return(channel); } } } throw new DiscordHttpException(new DiscordHttpError(DiscordError.UnknownChannel, "Channel was not found in cache")); } else { return(await((DiscordClient)client).GetChannelAsync(channelId)); } }