WebhookClient
classe · Source
The webhook client.
Extends: BaseClientImplements: Webhook
Constructor
Parameters
| Name | Type | Description |
|---|---|---|
data | WebhookClientData | The data of the webhook |
options? | ClientOptions | Options for the client |
Properties
id
The webhook's id Source
createdTimestamp
The timestamp the webhook was created at Source
createdAt
The time the webhook was created at Source
url
The URL of this webhook Source
options
The options the client was instantiated with Source
rest
The REST manager of the client Source
api
API shortcut Source
Methods
send
Sends a message with this webhook. Parameters
| Name | Type | Description |
|---|---|---|
options | string | MessagePayload | WebhookMessageOptions | The options to provide |
Returns: Promise<(Message\|APIMessage)>
// Send a basic message
webhook.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);// Send a basic message in a thread
webhook.send({ content: 'hello!', threadId: '836856309672348295' })
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);// Send a remote file
webhook.send({
files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
.then(console.log)
.catch(console.error);// Send a local file
webhook.send({
files: [{
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
}]
})
.then(console.log)
.catch(console.error);// 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);sendSlackMessage
Sends a raw slack message with this webhook. Parameters
| Name | Type | Description |
|---|---|---|
body | Object | The raw body to send |
Returns: Promise<boolean>
// 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);edit
Edits this webhook. Parameters
| Name | Type | Description |
|---|---|---|
options | WebhookEditData | Options for editing the webhook |
reason? | string | Reason for editing the webhook |
Returns: Promise<Webhook>Source
fetchMessage
Gets a message that was sent by this webhook. Parameters
| Name | Type | Description |
|---|---|---|
message | Snowflake | '@original' | The id of the message to fetch |
cacheOrOptions? | WebhookFetchMessageOptions | boolean | The 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
Edits a message that was sent by this webhook. Parameters
| Name | Type | Description |
|---|---|---|
message | MessageResolvable | '@original' | The message to edit |
options | string | MessagePayload | WebhookEditMessageOptions | The 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
Deletes the webhook. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for deleting this webhook |
Returns: Promise<void>Source
deleteMessage
Delete a message that was sent by this webhook. Parameters
| Name | Type | Description |
|---|---|---|
message | MessageResolvable | '@original' | The message to delete |
threadId? | Snowflake | The id of the thread this message belongs to |
Returns: Promise<void>Source
destroy
Destroys all assets used by the base client. Returns: voidSource
incrementMaxListeners
Increments max listeners by one, if they are not zero. Source
decrementMaxListeners
Decrements max listeners by one, if they are not zero. Source
Events
debug
Emitted for general debugging information. Parameters
| Name | Type | Description |
|---|---|---|
info | string | The debug information |
| Source |
rateLimit
Emitted when the client hits a rate limit while making a request Parameters
| Name | Type | Description |
|---|---|---|
rateLimitData | RateLimitData | Object containing the rate limit info |
| Source |
apiRequest
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
| Name | Type | Description |
|---|---|---|
request | APIRequest | The request that is about to be sent |
| Source |
apiResponse
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
| Name | Type | Description |
|---|---|---|
request | APIRequest | The request that triggered this response |
response | Response | The response received from the Discord API |
| Source |
invalidRequestWarning
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
| Name | Type | Description |
|---|---|---|
invalidRequestWarningData | InvalidRequestWarningData | Object containing the invalid request info |
| Source |