Exemplo n.º 1
0
        /// <summary>
        /// Adds an Enum as the avalible choices. This overrides all other choices added with AddChoice.
        /// </summary>
        /// <param name="enumType">Enum to generate choices from.</param>
        /// <returns>This builder</returns>
        public ApplicationCommandOptionBuilder WithChoices(Type enumType)
        {
            if (!enumType.IsEnum)
            {
                throw new Exception("Type is not an enum");
            }

            var names  = enumType.GetEnumNames();
            var values = enumType.GetEnumValues();

            List <ApplicationCommandOptionChoiceBuilder> choices = new();

            for (int i = 0; i < names.Length; i++)
            {
                var part = new ApplicationCommandOptionChoiceBuilder()
                           .WithName(names[i]);
                var val = values.GetValue(i);

                part.WithValue((int)val !);

                choices.Add(part);
            }

            Choices = choices;

            return(this);
        }
Exemplo n.º 2
0
        public ApplicationCommandOptionBuilder AddChoice(ApplicationCommandOptionChoiceBuilder choices)
        {
            // I think. Not completely sure.
            if (Options.Count >= 10)
            {
                throw new Exception("Cant have more than 10 choices.");
            }

            Choices.Add(choices);
            return(this);
        }