Skip to content

WebhookClient

classe · Source

The webhook client.

Extends: BaseClientImplements: Webhook

Constructor

new WebhookClient(data: WebhookClientData, options?: ClientOptions)

Parameters

NameTypeDescription
dataWebhookClientDataThe data of the webhook
options?ClientOptionsOptions for the client

Properties

id

id: Snowflake

The webhook's id Source

createdTimestamp

readonly

createdTimestamp: number

The timestamp the webhook was created at Source

createdAt

readonly

createdAt: Date

The time the webhook was created at Source

url

readonly

url: string

The URL of this webhook Source

options

options: ClientOptions

The options the client was instantiated with Source

rest

private

rest: RESTManager

The REST manager of the client Source

api

readonly · private

api: Object

API shortcut Source

Methods

send

async

async send(options: string | MessagePayload | WebhookMessageOptions): Promise<(Message|APIMessage)>

Sends a message with this webhook. Parameters

NameTypeDescription
optionsstring | MessagePayload | WebhookMessageOptionsThe options to provide

Returns: Promise<(Message\|APIMessage)>

js
// Send a basic message
webhook.send('hello!')
  .then(message => console.log(`Sent message: ${message.content}`))
  .catch(console.error);
js
// Send a basic message in a thread
webhook.send({ content: 'hello!', threadId: '836856309672348295' })
  .then(message => console.log(`Sent message: ${message.content}`))
  .catch(console.error);
js
// Send a remote file
webhook.send({
  files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
  .then(console.log)
  .catch(console.error);
js
// Send a local file
webhook.send({
  files: [{
    attachment: 'entire/path/to/file.jpg',
    name: 'file.jpg'
  }]
})
  .then(console.log)
  .catch(console.error);
js
// Send an embed with a local image inside
webhook.send({
  content: 'This is an embed',
  embeds: [{
    thumbnail: {
         url: 'attachment://file.jpg'
      }
   }],
   files: [{
      attachment: 'entire/path/to/file.jpg',
      name: 'file.jpg'
   }]
})
  .then(console.log)
  .catch(console.error);

Source

sendSlackMessage

async

async sendSlackMessage(body: Object): Promise<boolean>

Sends a raw slack message with this webhook. Parameters

NameTypeDescription
bodyObjectThe raw body to send

Returns: Promise<boolean>

js
// Send a slack message
webhook.sendSlackMessage({
  'username': 'Wumpus',
  'attachments': [{
    'pretext': 'this looks pretty cool',
    'color': '#F0F',
    'footer_icon': 'http://snek.s3.amazonaws.com/topSnek.png',
    'footer': 'Powered by sneks',
    'ts': Date.now() / 1_000
  }]
}).catch(console.error);

Source

edit

async

async edit(options: WebhookEditData, reason?: string): Promise<Webhook>

Edits this webhook. Parameters

NameTypeDescription
optionsWebhookEditDataOptions for editing the webhook
reason?stringReason for editing the webhook

Returns: Promise<Webhook>Source

fetchMessage

async

async fetchMessage(message: Snowflake | '@original', cacheOrOptions?: WebhookFetchMessageOptions | boolean): Promise<(Message|APIMessage)>

Gets a message that was sent by this webhook. Parameters

NameTypeDescription
messageSnowflake | '@original'The id of the message to fetch
cacheOrOptions?WebhookFetchMessageOptions | booleanThe options to provide to fetch the message.
A deprecated boolean may be passed instead to specify whether to cache the message. Default: {}.

Returns: Promise<(Message\|APIMessage)> — Returns the raw message data if the webhook was instantiated as a WebhookClient or if the channel is uncached, otherwise a Message will be returned Source

editMessage

async

async editMessage(message: MessageResolvable | '@original', options: string | MessagePayload | WebhookEditMessageOptions): Promise<(Message|APIMessage)>

Edits a message that was sent by this webhook. Parameters

NameTypeDescription
messageMessageResolvable | '@original'The message to edit
optionsstring | MessagePayload | WebhookEditMessageOptionsThe options to provide

Returns: Promise<(Message\|APIMessage)> — Returns the raw message data if the webhook was instantiated as a WebhookClient or if the channel is uncached, otherwise a Message will be returned Source

delete

async

async delete(reason?: string): Promise<void>

Deletes the webhook. Parameters

NameTypeDescription
reason?stringReason for deleting this webhook

Returns: Promise<void>Source

deleteMessage

async

async deleteMessage(message: MessageResolvable | '@original', threadId?: Snowflake): Promise<void>

Delete a message that was sent by this webhook. Parameters

NameTypeDescription
messageMessageResolvable | '@original'The message to delete
threadId?SnowflakeThe id of the thread this message belongs to

Returns: Promise<void>Source

destroy

destroy(): void

Destroys all assets used by the base client. Returns: voidSource

incrementMaxListeners

private

incrementMaxListeners()

Increments max listeners by one, if they are not zero. Source

decrementMaxListeners

private

decrementMaxListeners()

Decrements max listeners by one, if they are not zero. Source

Events

debug

debug: unknown

Emitted for general debugging information. Parameters

NameTypeDescription
infostringThe debug information
Source

rateLimit

rateLimit: unknown

Emitted when the client hits a rate limit while making a request Parameters

NameTypeDescription
rateLimitDataRateLimitDataObject containing the rate limit info
Source

apiRequest

apiRequest: unknown

Emitted before every API request. This event can emit several times for the same request, e.g. when hitting a rate limit. This is an informational event that is emitted quite frequently, it is highly recommended to check request.path to filter the data. Parameters

NameTypeDescription
requestAPIRequestThe request that is about to be sent
Source

apiResponse

apiResponse: unknown

Emitted after every API request has received a response. This event does not necessarily correlate to completion of the request, e.g. when hitting a rate limit. This is an informational event that is emitted quite frequently, it is highly recommended to check request.path to filter the data. Parameters

NameTypeDescription
requestAPIRequestThe request that triggered this response
responseResponseThe response received from the Discord API
Source

invalidRequestWarning

invalidRequestWarning: unknown

Emitted periodically when the process sends invalid requests to let users avoid the 10k invalid requests in 10 minutes threshold that causes a ban Parameters

NameTypeDescription
invalidRequestWarningDataInvalidRequestWarningDataObject containing the invalid request info
Source

Unofficial software. Not affiliated with or supported by Discord.