public ReactionMessage ToReactionMessage() { if (!_client.Guilds.TryGetValue(GuildId, out DiscordGuild guild)) { Console.WriteLine("Could not get the guild of this message, perhaps the bot have been removed from it? (Skipping ReactionMessage)"); return(null); } if (!guild.Channels.TryGetValue(ChannelId, out DiscordChannel channel)) { Console.WriteLine("Could not get the channel of this message, perhaps the bot have not access to it anymore? (Skipping ReactionMessage)"); return(null); } DiscordMessage message; try { message = channel.GetMessageAsync(MessageId).Result; } catch (Exception e) { Console.WriteLine("Could not get the channel of this message, perhaps it has been removed? (Skipping ReactionMessage)"); Console.WriteLine(e); return(null); } Dictionary <DiscordEmoji, DiscordRole> reactionRules = new Dictionary <DiscordEmoji, DiscordRole>(); foreach (SerializedRule rule in Rules) { DiscordEmoji emoji; if (rule.IsGuildEmoji) { ulong id = ulong.Parse(rule.EmojiNameOrId); if (!DiscordEmoji.TryFromGuildEmote(_client, id, out emoji)) { GuildEventLogger.Instance.LogWarning(guild, $"Could not load emoji {rule.EmojiNameOrId}. Has it been removed or renamed? (Skipping this rule)"); continue; } } else { if (!DiscordEmoji.TryFromName(_client, rule.EmojiNameOrId, out emoji)) { GuildEventLogger.Instance.LogWarning(guild, $"Could not load emoji {rule.EmojiNameOrId}. Has it been removed or renamed? (Skipping this rule)"); continue; } } if (!guild.Roles.TryGetValue(rule.RoleId, out DiscordRole role)) { GuildEventLogger.Instance.LogWarning(guild, $"Could not load role ID {rule.RoleId}. Has it been removed? (Skipping this rule)"); continue; } reactionRules.Add(emoji, role); } return(new ReactionMessage(message, reactionRules)); }