Webhook

export class Webhook<Type extends WebhookType = WebhookType>
export class Webhook<Type extends WebhookType = WebhookType>
Represents a webhook.
NameConstraintsOptionalDefaultDescription
TypeWebhookTypeYesWebhookTypeNone
applicationId:Type extends WebhookType.Application ? Snowflake : null
The application that created this webhook
avatar:string | null
The avatar for the webhook
The channel the webhook belongs to
channelId:Snowflake
The id of the channel the webhook belongs to
Readonly
client:Client
The client that instantiated the webhook
Readonly
createdAt:Date
The time the webhook was created at
Readonly
createdTimestamp:number
The timestamp the webhook was created at
guildId:Snowflake
The guild the webhook belongs to
The webhook's id
name:string
The name of the webhook
owner:Type extends WebhookType.Incoming ? User | APIUser | null : User | APIUser
The owner of the webhook
The source channel of the webhook
sourceGuild:Type extends WebhookType.ChannelFollower ? Guild | APIPartialGuild : null
The source guild of the webhook
token:Type extends WebhookType.Incoming ? string : Type extends WebhookType.ChannelFollower ? null : string | null
The token for the webhook, unavailable for follower webhooks and webhooks owned by another application.
type:Type
The type of the webhook
Readonly
url:string
The URL of this webhook
avatarURL(options?):string | null
A link to the webhook's avatar.
Returns
NameTypeOptionalDescription
optionsImageURLOptionsYesOptions for the image URL
delete(reason?):Promise<void>
Deletes the webhook.
NameTypeOptionalDescription
reasonstringYesReason for deleting this webhook
deleteMessage(message, threadId?):Promise<void>
Delete a message that was sent by this webhook.
NameTypeOptionalDescription
messageMessageResolvable | '@original'NoThe message to delete
threadIdSnowflakeYesThe id of the thread this message belongs to
edit(options):Promise<Webhook>
Edits this webhook.
NameTypeOptionalDescription
optionsWebhookEditOptionsNoOptions for editing the webhook
editMessage(message, options):Promise<Message>
Edits a message that was sent by this webhook.
Returns
Returns the message edited by this webhook
NameTypeOptionalDescription
messageMessageResolvableNoThe message to edit
optionsstring | MessagePayload | WebhookMessageEditOptionsNoThe options to provide
fetchMessage(message, options?):Promise<Message>
Gets a message that was sent by this webhook.
Returns
Returns the message sent by this webhook
NameTypeOptionalDescription
messageSnowflakeNoThe id of the message to fetch
optionsWebhookFetchMessageOptionsYesThe options to provide to fetch the message.
isApplicationCreated():this is Webhook<WebhookType.Application>
Whether this webhook is created by an application.
isChannelFollower():this is Webhook<WebhookType.ChannelFollower>
Whether or not this webhook is a channel follower webhook.
isIncoming():this is Webhook<WebhookType.Incoming>
Whether or not this webhook is an incoming webhook.
isUserCreated():this is Webhook<WebhookType.Incoming> & { owner: User | APIUser; }
Whether this webhook is created by a user.
send(options):Promise<Message>
Sends a message with this webhook.
Example
// Send a basic message
webhook.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
// Send a basic message
webhook.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
Example
// 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 basic message in a thread
webhook.send({ content: 'hello!', threadId: '836856309672348295' })
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
Example
// 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 remote file
webhook.send({
files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
.then(console.log)
.catch(console.error);
Example
// Send a local file
webhook.send({
files: [{
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
}]
})
.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);
Example
// 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);
// 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);
NameTypeOptionalDescription
optionsstring | MessagePayload | WebhookMessageCreateOptionsNoThe options to provide
sendSlackMessage(body):Promise<boolean>
Sends a raw slack message with this webhook.
Example
// 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);
// 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);
NameTypeOptionalDescription
bodyobjectNoThe raw body to send