export class Webhook<Type extends WebhookType = WebhookType>
Represents a webhook.
Type Parameters
optionalWebhookType = WebhookType Type? extends
Type extends WebhookType.Application ? Snowflake : null applicationId :
The application that created this webhook
readonlyTextChannel | VoiceChannel | NewsChannel | StageChannel | ForumChannel | MediaChannel | null channel :
The channel the webhook belongs to
Snowflake channelId :
The id of the channel the webhook belongs to
readonlyClient client :
The client that instantiated the webhook
readonlyDate createdAt :
The time the webhook was created at
readonlynumber createdTimestamp :
The timestamp the webhook was created at
Snowflake guildId :
The guild the webhook belongs to
Snowflake id :
The webhook's id
string name :
The name of the webhook
The owner of the webhook
Type extends WebhookType.ChannelFollower ? NewsChannel | APIPartialChannel : null sourceChannel :
The source channel of the webhook
Type extends WebhookType.ChannelFollower ? Guild | APIPartialGuild : null sourceGuild :
The source guild of the webhook
Type extends WebhookType.Incoming ? string : Type extends WebhookType.ChannelFollower ? null : string | null token :
The token for the webhook, unavailable for follower webhooks and webhooks owned by another application.
readonlystring url :
The URL of this webhook
avatarURLoptions?: ImageURLOptions) : string | null (
A link to the webhook's avatar.
deleteMessagemessage: MessageResolvable | '@original'threadId?: Snowflake) : Promise<void> (
Delete a message that was sent by this webhook.
editoptions: WebhookEditOptions) : Promise<Webhook> (
Edits this webhook.
editMessagemessage: MessageResolvableoptions: string | MessagePayload | WebhookMessageEditOptions) : Promise<Message> (
Edits a message that was sent by this webhook.
Returns: Returns the message edited by this webhook
fetchMessagemessage: Snowflakeoptions?: WebhookFetchMessageOptions) : Promise<Message> (
Gets a message that was sent by this webhook.
Returns: Returns the message sent by this webhook
isApplicationCreatedthis is Webhook<WebhookType.Application> () :
Whether this webhook is created by an application.
isChannelFollowerthis is Webhook<WebhookType.ChannelFollower> () :
Whether or not this webhook is a channel follower webhook.
isIncomingthis is Webhook<WebhookType.Incoming> () :
Whether or not this webhook is an incoming webhook.
isUserCreatedthis is Webhook<WebhookType.Incoming> & { owner: User | APIUser; } () :
Whether this webhook is created by a user.
sendoptions: string | MessagePayload | WebhookMessageCreateOptions) : Promise<Message> (
Sends a message with this webhook.
// 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);
Sends a raw slack message with this webhook.
// 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);