public static Language GetDefaultLanguage(IGuild guild, IChannel channel = null, string specifiedLanguage = null) { // Check if a language was specified if (specifiedLanguage == null) { // Check if this is not a DM if (guild != null) { // Attempt to get the GuildSettings for this guild GuildSettings guildSettings = Configuration.LoadedConfiguration.DiscordConfig.GuildSettings.Where(x => x.GuildId == guild.Id).FirstOrDefault(); // Check if there is a GuildSettings if (guildSettings != null) { // Check if there is a channel specified if (channel != null) { // Attempt to get a DynamicSettingsData for this channel DynamicSettingsData channelSettings = guildSettings.ChannelSettings.Where(c => c.Key == channel.Id).FirstOrDefault().Value; // Check if it exists if (channelSettings != null) { // Return the channel's language return((Language)channelSettings.GetSetting("language")); } } // Return the guild's default language return((Language)guildSettings.GetSetting("default_language")); } } // Default to en-US return(Language.EnglishUS); } else { try { return(LanguageExtensions.FromCode(specifiedLanguage)); } catch (Exception) { throw new LocalizedException("discord.error.bad_code"); } } }