Exemple #1
0
        public static async Task <RestGuildTemplate> CreateTemplateAsync(IGuild guild, BaseDiscordClient client, string name, Optional <string> description, bool withSnapshot, RequestOptions options)
        {
            CreateTemplateParams apiargs = new CreateTemplateParams
            {
                Name = name
            };

            if (description.IsSpecified)
            {
                apiargs.Description = description.Value;
            }

            if (withSnapshot)
            {
                GuildTemplateSnapshotJson model = await client.ApiClient.CreateTemplateAsync <API.GuildTemplateSnapshotJson>(guild.Id, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
            else
            {
                GuildTemplateJson model = await client.ApiClient.CreateTemplateAsync <API.GuildTemplateJson>(guild.Id, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
        }
Exemple #2
0
        public static async Task <RestGuildTemplate> ModifyTemplateAsync(IGuild guild, BaseDiscordClient client, string code, Action <TemplateProperties> func, bool withSnapshot, RequestOptions options)
        {
            if (func == null)
            {
                throw new ArgumentNullException(paramName: nameof(func));
            }
            TemplateProperties props = new TemplateProperties();

            func(props);

            CreateTemplateParams apiargs = new CreateTemplateParams();

            if (props.Name.IsSpecified)
            {
                apiargs.Name = props.Name.Value;
            }

            if (props.Description.IsSpecified)
            {
                apiargs.Description = props.Description.Value;
            }


            if (withSnapshot)
            {
                GuildTemplateSnapshotJson model = await client.ApiClient.ModifyTemplateAsync <API.GuildTemplateSnapshotJson>(guild.Id, code, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
            else
            {
                GuildTemplateJson model = await client.ApiClient.ModifyTemplateAsync <API.GuildTemplateJson>(guild.Id, code, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
        }