Table of Contents

Class WebhookClient

Namespace
NetCord.Rest
Assembly
NetCord.dll

A specialized client that can be used to interact with webhook endpoints.

public sealed class WebhookClient : IDisposable
Inheritance
WebhookClient
Implements
Inherited Members

Constructors

WebhookClient(ulong, string, WebhookClientConfiguration?)

Creates a WebhookClient from its ID, token, and optional configuration.

public WebhookClient(ulong webhookId, string webhookToken, WebhookClientConfiguration? configuration = null)

Parameters

webhookId ulong
The ID of the webhook to use.
webhookToken string
The token to use for authorization.
configuration WebhookClientConfiguration

The configuration to pass to the client.

Properties

Id

The ID of the webhook to use.

public ulong Id { get; }

Property Value

ulong

Token

The token to use for authorization.

public string Token { get; }

Property Value

string

Methods

DeleteAsync(RestRequestProperties?, CancellationToken)

Deletes a webhook permanently, using the specified token.

public Task DeleteAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

Remarks

Requires the ManageWebhooks permission, and fires a WebhooksUpdate event.

DeleteMessageAsync(ulong, ulong?, RestRequestProperties?, CancellationToken)

Deletes a previously-sent webhook message permanently.

public Task DeleteMessageAsync(ulong messageId, ulong? threadId = null, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

messageId ulong

The ID of the message to delete.

threadId ulong?

The ID of the thread the message is in.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

Dispose()

public void Dispose()

ExecuteAsync(WebhookMessageProperties, bool, ulong?, bool, RestRequestProperties?, CancellationToken)

Executes a webhook with the given parameters, optionally returning the message result.

public Task<RestMessage?> ExecuteAsync(WebhookMessageProperties message, bool wait = false, ulong? threadId = null, bool withComponents = true, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

message WebhookMessageProperties

The message to send through the webhook.

wait bool

If set, the returned RestMessage will contain the sent message, otherwise null.

threadId ulong?

Optional ID of the thread to send the message in, within the webhook's target channel. Can be null.

withComponents bool

Whether to respect the message's Components.

When enabled, allows application-owned webhooks to use all components, and non-owned webhooks to use non-interactive components.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

GetAsync(RestRequestProperties?, CancellationToken)

Retrieves a Webhook object for the given ID, using the specified webhook token.

public Task<Webhook> GetAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<Webhook>

Remarks

This endpoint does not require authentication.

GetMessageAsync(ulong, ulong?, RestRequestProperties?, CancellationToken)

Returns a previously-sent webhook message.

public Task<RestMessage> GetMessageAsync(ulong messageId, ulong? threadId = null, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

messageId ulong

The ID of the message to retrieve.

threadId ulong?

The ID of the thread the message is in.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

ModifyAsync(Action<WebhookOptions>, RestRequestProperties?, CancellationToken)

Modifies a webhook using the specified token, returning the updated Webhook object on success.

public Task<Webhook> ModifyAsync(Action<WebhookOptions> action, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

action Action<WebhookOptions>

The modification to perform on the webhook.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<Webhook>

Remarks

Requires the ManageWebhooks permission, and fires a WebhooksUpdate event.

Does not allow modifiying the ChannelId property.

ModifyMessageAsync(ulong, Action<MessageOptions>, ulong?, bool, RestRequestProperties?, CancellationToken)

Modifies a previously-sent webhook message.

public Task<RestMessage> ModifyMessageAsync(ulong messageId, Action<MessageOptions> action, ulong? threadId = null, bool withComponents = true, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

messageId ulong

The ID of the message to modify.

action Action<MessageOptions>

The modification to apply to the message.

threadId ulong?

The ID of the thread the message is in.

withComponents bool

Whether to respect the modification's Components.

When enabled, allows application-owned webhooks to use all components, and non-owned webhooks to use non-interactive components.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>