public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null)
 {
     Name        = name;
     Description = description;
     Options     = Optional.Create(options);
     Type        = type;
 }
        internal SocketCommandBaseData(DiscordSocketClient client, Model model, ulong?guildId)
            : base(client, model.Id)
        {
            Type = model.Type;

            if (model.Resolved.IsSpecified)
            {
                ResolvableData = new SocketResolvableData <Model>(client, guildId, model);
            }
        }
示例#3
0
        /// <summary>
        /// Marks this method as a context menu.
        /// </summary>
        /// <param name="type">The type of the context menu.</param>
        /// <param name="name">The name of the context menu.</param>
        /// <param name="defaultPermission">Sets whether the command should be enabled by default.</param>
        public ContextMenuAttribute(ApplicationCommandType type, string name, bool defaultPermission = true)
        {
            if (type == ApplicationCommandType.SlashCommand)
            {
                throw new ArgumentException("Context menus cannot be of type SlashCommand.");
            }

            this.Type = type;
            this.Name = name;
            this.DefaultPermission = defaultPermission;
        }
示例#4
0
        /// <summary>
        /// Creates a new Application Command Builder
        /// </summary>
        /// <param name="name">Name of the command</param>
        /// <param name="description">Description of the command</param>
        /// <param name="type">Command type</param>
        public ApplicationCommandBuilder(string name, string description, ApplicationCommandType type)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(name));
            }
            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(description));
            }

            _options = new List <CommandOption>();
            Command  = new CommandCreate
            {
                Name        = name,
                Description = description,
                Type        = type,
                Options     = _options
            };
        }
示例#5
0
        /// <summary>
        /// Creates a new instance of a <see cref="DiscordApplicationCommand"/>.
        /// </summary>
        /// <param name="name">The name of the command.</param>
        /// <param name="description">The description of the command.</param>
        /// <param name="options">Optional parameters for this command.</param>
        /// <param name="defaultPermission">Whether the command is enabled by default when the application is added to a guild.</param>
        public DiscordApplicationCommand(string name, string description, IEnumerable <DiscordApplicationCommandOption> options = null, bool?defaultPermission = null, ApplicationCommandType type = ApplicationCommandType.SlashCommand)
        {
            if (type == ApplicationCommandType.SlashCommand)
            {
                if (!Utilities.IsValidSlashCommandName(name))
                {
                    throw new ArgumentException("Invalid slash command name specified. It must be below 32 characters and not contain any whitespace.", nameof(name));
                }
                if (name.Any(ch => char.IsUpper(ch)))
                {
                    throw new ArgumentException("Slash command name cannot have any upper case characters.", nameof(name));
                }
                if (description.Length > 100)
                {
                    throw new ArgumentException("Slash command description cannot exceed 100 characters.", nameof(description));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(description))
                {
                    throw new ArgumentException("Context menus do not support descriptions.");
                }

                if (options?.Any() ?? false)
                {
                    throw new ArgumentException("Context menus do not support options.");
                }
            }

            var optionsList = options != null ? new ReadOnlyCollection <DiscordApplicationCommandOption>(options.ToList()) : null;

            this.Type              = type;
            this.Name              = name;
            this.Description       = description;
            this.Options           = optionsList;
            this.DefaultPermission = defaultPermission;
        }
 /// <summary>
 ///     Sets <see cref="CommandType"/>.
 /// </summary>
 /// <param name="commandType">New value of the <see cref="CommandType"/>.</param>
 /// <returns>
 ///     The builder instance.
 /// </returns>
 public ContextCommandBuilder SetType(ApplicationCommandType commandType)
 {
     CommandType = commandType;
     return(this);
 }
示例#7
0
 protected ApplicationCommand(ApplicationCommandType type)
 {
     this.type = type;
 }
示例#8
0
 internal ContextCommandAttribute(string name, ApplicationCommandType commandType, RunMode runMode = RunMode.Default)
 {
     Name        = name;
     CommandType = commandType;
     RunMode     = runMode;
 }