コード例 #1
0
        public static CreateApplicationCommandJsonRestRequestContent ToContent(this LocalApplicationCommand command, IJsonSerializer serializer)
        {
            Guard.IsNotNull(command);

            var content = new CreateApplicationCommandJsonRestRequestContent
            {
                Name = command.Name.Value,
                DefaultPermission = command.IsEnabledByDefault
            };

            if (command is LocalSlashCommand slashCommand)
            {
                content.Type        = ApplicationCommandType.Slash;
                content.Description = slashCommand.Description;
                content.Options     = Optional.Convert(slashCommand.Options, options => options?.Select(option => option?.ToModel(serializer)).ToArray());
            }
            else if (command is LocalUserContextMenuCommand)
            {
                content.Type = ApplicationCommandType.User;
            }
            else if (command is LocalMessageContextMenuCommand)
            {
                content.Type = ApplicationCommandType.Message;
            }

            return(content);
        }
コード例 #2
0
        public static Task <IApplicationCommand> CreateApplicationCommandAsync(this IGuild guild,
                                                                               Snowflake applicationId, LocalApplicationCommand command,
                                                                               IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = guild.GetRestClient();

            return(client.CreateGuildApplicationCommandAsync(applicationId, guild.Id, command, options, cancellationToken));
        }
        public static async Task <IApplicationCommand> CreateGuildApplicationCommandAsync(this IRestClient client,
                                                                                          Snowflake applicationId, Snowflake guildId, LocalApplicationCommand command,
                                                                                          IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var content = command.ToContent(client.ApiClient.Serializer);
            var model   = await client.ApiClient.CreateGuildApplicationCommandAsync(applicationId, guildId, content, options, cancellationToken).ConfigureAwait(false);

            return(TransientApplicationCommand.Create(client, model));
        }