예제 #1
0
        /// <summary>
        /// Handles adding <see cref="SelectMenuComponent"/> to the given interaction
        /// </summary>
        /// <param name="sm">The <see cref="SelectMenuAttribute"/> that represents the select menu handler</param>
        /// <param name="method">The method that will be triggered when handling the interaction</param>
        /// <param name="type">The type of the class that will handle the interaction</param>
        /// <param name="builder">The <see cref="ComponentBuilder"/></param>
        /// <param name="channel">The channel the interaction happened in</param>
        /// <param name="user">The user that triggered the interaction</param>
        /// <param name="message">The message that triggered the interaction</param>
        /// <returns>A task representing the completion of the request</returns>
        /// <exception cref="ArgumentException">Thrown when the min or max values field on the select menu are less than 1</exception>
        public async Task HandleSelectMenu(SelectMenuAttribute sm, MethodInfo method, Type type, ComponentBuilder builder, IChannel channel, IUser user, IMessage?message)
        {
            if (sm.MinValues < 1 || sm.MaxValues < 1)
            {
                throw new ArgumentException("Min/Max values for Select Menu must be 1 or greater.", "(Max/Min)Values");
            }

            var id      = _handlers.IdFromMethod(method);
            var options = new List <SelectMenuOptionBuilder>();

            if (!string.IsNullOrEmpty(sm.OptionsMethod))
            {
                options.AddRange(await MenuOptionsFromMethod(sm.OptionsMethod, type, channel, user, message));
            }

            options.AddRange(MenuOptionsFromAttributes(method));

            builder.WithSelectMenu(id, options, sm.Placeholder, sm.MinValues, sm.MaxValues, sm.Disabled, sm.Row);
        }