/// <summary> /// Modifies the webhook /// </summary> /// <param name="properties">Options for modifying the webhook</param> public void Modify(WebhookProperties properties) { Hook hook = Client.ModifyChannelWebhook(Id, properties); Name = hook.Name; AvatarId = hook.AvatarId; ChannelId = hook.ChannelId; }
public static async Task <WebhookModel> ModifyAsync(DiscordWebhookClient client, Action <WebhookProperties> func, RequestOptions options) { WebhookProperties args = new WebhookProperties(); func(args); ModifyWebhookParams apiArgs = new ModifyWebhookParams { Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create <ImageModel?>(), Name = args.Name }; if (!apiArgs.Avatar.IsSpecified && client.Webhook.AvatarId != null) { apiArgs.Avatar = new ImageModel(client.Webhook.AvatarId); } return(await client.ApiClient.ModifyWebhookAsync(client.Webhook.Id, apiArgs, options).ConfigureAwait(false)); }
public void Modify(WebhookProperties properties) { if (properties.Name == null) { properties.Name = Name; } if (!properties.AvatarSet) { properties.Avatar = GetAvatar(); } if (!properties.ChannelProperty.Set) { properties.ChannelId = ChannelId; } Hook hook = Client.ModifyChannelWebhook(Id, properties); Name = hook.Name; AvatarId = hook.AvatarId; ChannelId = hook.ChannelId; }
/// <summary> /// Modifies a webhook /// </summary> /// <param name="webhookId">ID of the webhook</param> /// <param name="properties">Options for modifyiing a webhook</param> /// <returns>The modified webhook</returns> public static Hook ModifyChannelWebhook(this DiscordClient client, ulong webhookId, WebhookProperties properties) { return(client.HttpClient.Patch($"/webhooks/{webhookId}", JsonConvert.SerializeObject(properties)).Deserialize <Hook>().SetClient(client)); }
/// <summary> /// Creates a webhook /// </summary> /// <param name="channelId">ID of the channel</param> /// <param name="properties">Options for creating/modifying the webhook</param> /// <returns>The created webhook</returns> public static Hook CreateChannelWebhook(this DiscordClient client, ulong channelId, WebhookProperties properties) { properties.ChannelId = channelId; Hook hook = client.HttpClient.Post($"/channels/{channelId}/webhooks", JsonConvert.SerializeObject(properties)).Deserialize <Hook>().SetClient(client); hook.Modify(properties); return(hook); }