Skip to content

Webhook

classe · Source

Represents a webhook.

Properties

client

readonly

client: Client

The client that instantiated the webhook Source

name

name: string

The name of the webhook Source

token

nullable

token: string

The token for the webhook, unavailable for follower webhooks and webhooks owned by another application. Source

avatar

nullable

avatar: string

The avatar for the webhook Source

id

id: Snowflake

The webhook's id Source

type

type: WebhookType

The type of the webhook Source

guildId

guildId: Snowflake

The guild the webhook belongs to Source

channelId

channelId: Snowflake

The id of the channel the webhook belongs to Source

owner

nullable

owner: User | APIUser

The owner of the webhook Source

sourceGuild

nullable

sourceGuild: Guild | APIGuild

The source guild of the webhook Source

sourceChannel

nullable

sourceChannel: NewsChannel | APIChannel

The source channel of the webhook Source

channel

readonly · nullable

channel: TextChannel | VoiceChannel | NewsChannel | ForumChannel | MediaChannel

The channel the webhook belongs to 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

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

avatarURL

avatarURL(options?: StaticImageURLOptions): string

A link to the webhook's avatar. Parameters

NameTypeDescription
options?StaticImageURLOptionsOptions for the Image URL Default: {}.

Returns: stringSource

isChannelFollower

isChannelFollower(): boolean

Whether or not this webhook is a channel follower webhook. Returns: booleanSource

isIncoming

isIncoming(): boolean

Whether or not this webhook is an incoming webhook. Returns: booleanSource

Unofficial software. Not affiliated with or supported by Discord.