public object Parse(SocketInteractionDataOption dataOption) { switch (Type) { case ApplicationCommandOptionType.Boolean: if (Nullable) { return((bool?)dataOption); } else { return((bool)dataOption); } case ApplicationCommandOptionType.Integer: if (Nullable) { return((int?)dataOption); } else { return((int)dataOption); } case ApplicationCommandOptionType.String: return((string)dataOption); case ApplicationCommandOptionType.Channel: return((SocketGuildChannel)dataOption); case ApplicationCommandOptionType.Role: return((SocketRole)dataOption); case ApplicationCommandOptionType.User: return((SocketGuildUser)dataOption); case ApplicationCommandOptionType.SubCommandGroup: throw new NotImplementedException(); case ApplicationCommandOptionType.SubCommand: throw new NotImplementedException(); } throw new NotImplementedException($"There is no such type of data... unless we missed it. Please report this error on the Discord.Net github page! Type: {Type}"); }
/// <summary> /// Get the interaction data from the name of the parameter we want to fill in. /// </summary> private static bool TryGetInteractionDataOption(IReadOnlyCollection <SocketInteractionDataOption> data, string name, out SocketInteractionDataOption dataOption) { if (data == null) { dataOption = null; return(false); } foreach (var option in data) { if (option.Name != name.ToLower()) { continue; } dataOption = option; return(true); } dataOption = null; return(false); }