示例#1
0
        /// <summary>
        ///     Adds slash command builder to <see cref="SlashCommands"/>.
        /// </summary>
        /// <param name="configure"><see cref="SlashCommandBuilder"/> factory.</param>
        /// <returns>
        ///     The builder instance.
        /// </returns>
        public ModuleBuilder AddSlashCommand(Action <SlashCommandBuilder> configure)
        {
            var command = new SlashCommandBuilder(this);

            configure(command);
            _slashCommands.Add(command);
            return(this);
        }
示例#2
0
        /// <summary>
        ///     Adds slash command builder to <see cref="SlashCommands"/>.
        /// </summary>
        /// <param name="name">Name of the command.</param>
        /// <param name="callback">Command callback to be executed.</param>
        /// <param name="configure"><see cref="SlashCommandBuilder"/> factory.</param>
        /// <returns>
        ///     The builder instance.
        /// </returns>
        public ModuleBuilder AddSlashCommand(string name, ExecuteCallback callback, Action <SlashCommandBuilder> configure)
        {
            var command = new SlashCommandBuilder(this, name, callback);

            configure(command);
            _slashCommands.Add(command);
            return(this);
        }
示例#3
0
        internal SlashCommandInfo(Builders.SlashCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
        {
            Description         = builder.Description;
            DefaultPermission   = builder.DefaultPermission;
            Parameters          = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
            FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray();

            for (var i = 0; i < FlattenedParameters.Count - 1; i++)
            {
                if (!FlattenedParameters.ElementAt(i).IsRequired&& FlattenedParameters.ElementAt(i + 1).IsRequired)
                {
                    throw new InvalidOperationException("Optional parameters must appear after all required parameters, ComplexParameters with optional parameters must be located at the end.");
                }
            }

            _flattenedParameterDictionary = FlattenedParameters?.ToDictionary(x => x.Name, x => x).ToImmutableDictionary();
        }
示例#4
0
 internal SlashCommandInfo(Builders.SlashCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
 {
     Description       = builder.Description;
     DefaultPermission = builder.DefaultPermission;
     Parameters        = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
 }