Table of Contents

Class Webhook

Namespace
NetCord.Rest
Assembly
NetCord.dll

Represents a webhook, a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use.

public class Webhook : ClientEntity, IEntity, ISpanFormattable, IFormattable, IEquatable<Entity>, IJsonModel<JsonWebhook>
Inheritance
Webhook
Implements
Derived
Inherited Members

Constructors

Webhook(JsonWebhook, RestClient)

public Webhook(JsonWebhook jsonModel, RestClient client)

Parameters

jsonModel JsonWebhook
client RestClient

Properties

ApplicationId

The ID of the bot or OAuth2 application that created this webhook.

public ulong? ApplicationId { get; }

Property Value

ulong?

AvatarHash

The default user avatar hash of the webhook.

public string? AvatarHash { get; }

Property Value

string

Channel

The channel that this webhook is following.

public Channel? Channel { get; }

Property Value

Channel

Remarks

This property is null if Type is not ChannelFollower, or if the Creator has lost access to the guild where the Channel resides.

ChannelId

The channel ID this webhook targets. Can be null.

public ulong? ChannelId { get; }

Property Value

ulong?

Creator

The User this webhook was created by.

public User? Creator { get; }

Property Value

User

Remarks

This property is null if the webhook was retrieved using its token.

Guild

The guild of the channel followed by this webhook.

public RestGuild? Guild { get; }

Property Value

RestGuild

Remarks

This property is null if Type is not ChannelFollower, or if the Creator has lost access to the guild where the Channel resides.

GuildId

The guild ID this webhook targets. Can be null.

public ulong? GuildId { get; }

Property Value

ulong?

Id

The ID of the webhook.

public override ulong Id { get; }

Property Value

ulong

Name

The default name of the webhook.

public string? Name { get; }

Property Value

string

Remarks

A webhook name is valid if:

  • The string length is between 1 and 80 characters.
  • It does not contain the substrings clyde or discord (case-insensitive).
  • It follows Discord's nickname guidelines, found here.

Type

The type of the webhook.

public WebhookType Type { get; }

Property Value

WebhookType

Url

The URL used for executing the webhook.

public string? Url { get; }

Property Value

string

Methods

CreateFromJson(JsonWebhook, RestClient)

public static Webhook CreateFromJson(JsonWebhook jsonModel, RestClient client)

Parameters

jsonModel JsonWebhook
client RestClient

Returns

Webhook

DeleteAsync(RestRequestProperties?, CancellationToken)

Deletes a webhook permanently.

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

Fires a WebhooksUpdate event.

GetAsync(RestRequestProperties?, CancellationToken)

Retrieves a Webhook object for the given ID.

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>

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

Modifies a webhook, 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.