public static async Task <IReadOnlyCollection <RestGuildCommand> > BulkOverwriteGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties[] properties, RequestOptions options = null) { var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(client, guildId, properties, options); return(models.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray()); }
internal static async Task <RestGuildCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, SlashCommandCreationProperties args, RequestOptions options = null) { Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); Preconditions.NotNullOrEmpty(args.Description, nameof(args.Description)); if (args.Options.IsSpecified) { if (args.Options.Value.Count > 10) { throw new ArgumentException("Option count must be 10 or less"); } foreach (var item in args.Options.Value) { Preconditions.NotNullOrEmpty(item.Name, nameof(item.Name)); Preconditions.NotNullOrEmpty(item.Description, nameof(item.Description)); } } var model = new CreateApplicationCommandParams() { Name = args.Name, Description = args.Description, Options = args.Options.IsSpecified ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional <Discord.API.ApplicationCommandOption[]> .Unspecified }; var cmd = await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); return(RestGuildCommand.Create(client, cmd, guildId)); }
public static async Task <RestGuildCommand> GetGuildApplicationCommandAsync(BaseDiscordClient client, ulong id, ulong guildId, RequestOptions options = null) { var model = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, id, options); return(model != null?RestGuildCommand.Create(client, model, guildId) : null); }
public static async Task <RestGuildCommand> CreateGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties properties, RequestOptions options = null) { var model = await InteractionHelper.CreateGuildCommandAsync(client, guildId, properties, options); return(RestGuildCommand.Create(client, model, guildId)); }
internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, RestApplicationCommandType type, ulong guildId = 0) { return(type switch { RestApplicationCommandType.GlobalCommand => RestGlobalCommand.Create(client, model), RestApplicationCommandType.GuildCommand => RestGuildCommand.Create(client, model, guildId), _ => null });
public static async Task <IReadOnlyCollection <RestGuildCommand> > GetGuildApplicationCommands(BaseDiscordClient client, ulong guildId, RequestOptions options) { var response = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, options).ConfigureAwait(false); if (!response.Any()) { return(new RestGuildCommand[0].ToImmutableArray()); } return(response.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray()); }
internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, RestApplicationCommandType type, ulong guildId = 0) { if (type == RestApplicationCommandType.GlobalCommand) { return(RestGlobalCommand.Create(client, model)); } if (type == RestApplicationCommandType.GuildCommand) { return(RestGuildCommand.Create(client, model, guildId)); } return(null); }
internal static async Task <RestGuildCommand[]> CreateGuildCommands(BaseDiscordClient client, ulong guildId, List <SlashCommandCreationProperties> argsList, RequestOptions options = null) { Preconditions.NotNull(argsList, nameof(argsList)); Preconditions.NotEqual(argsList.Count, 0, nameof(argsList)); var models = new List <CreateApplicationCommandParams>(argsList.Count); foreach (var args in argsList) { Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); Preconditions.NotNullOrEmpty(args.Description, nameof(args.Description)); if (args.Options.IsSpecified) { if (args.Options.Value.Count > 25) { throw new ArgumentException("Option count must be 25 or less"); } foreach (var item in args.Options.Value) { Preconditions.NotNullOrEmpty(item.Name, nameof(item.Name)); Preconditions.NotNullOrEmpty(item.Description, nameof(item.Description)); } } var model = new CreateApplicationCommandParams { Name = args.Name, Description = args.Description, Options = args.Options.IsSpecified ? args.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified }; models.Add(model); } var cmd = await client.ApiClient.CreateGuildApplicationCommandsAsync(models, guildId, options).ConfigureAwait(false); return(cmd.Select(x => RestGuildCommand.Create(client, x, guildId)).ToArray()); }
internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, ulong?guildId) { return(guildId.HasValue ? RestGuildCommand.Create(client, model, guildId.Value) : RestGlobalCommand.Create(client, model)); }