Class: Webhook

Webhook

Represents a webhook.

Constructor

new Webhook()

Source:

Members

(nullable) avatar :string

The avatar for the webhook
Type:
  • string
Source:

channelID :Snowflake

The channel the webhook belongs to
Type:
Source:

(readonly) client :Client

The client that instantiated the webhook
Type:
Source:

(readonly) createdAt :Date

The time the webhook was created at
Type:
  • Date
Source:

(readonly) createdTimestamp :number

The timestamp the webhook was created at
Type:
  • number
Source:

guildID :Snowflake

The guild the webhook belongs to
Type:
Source:

id :Snowflake

The ID of the webhook
Type:
Source:

name :string

The name of the webhook
Type:
  • string
Source:

owner :User|Object

The owner of the webhook
Type:
Source:

(nullable) token :string

The token for the webhook
Type:
  • string
Source:

type :WebhookTypes

The type of the webhook
Type:
Source:

(readonly) url :string

The url of this webhook
Type:
  • string
Source:

Methods

avatarURL(optionsopt) → {string}

A link to the webhook's avatar.
Parameters:
Name Type Attributes Default Description
options ImageURLOptions <optional>
{} Options for the Image URL
Source:
Returns:
Type
string

delete(reasonopt) → {Promise}

Deletes the webhook.
Parameters:
Name Type Attributes Description
reason string <optional>
Reason for deleting this webhook
Source:
Returns:
Type
Promise

edit(options, reasonopt) → {Promise.<Webhook>}

Edits the webhook.
Parameters:
Name Type Attributes Description
options Object Options
Properties
Name Type Attributes Default Description
name string <optional>
this.name New name for this webhook
avatar BufferResolvable <optional>
New avatar for this webhook
channel ChannelResolvable <optional>
New channel for this webhook
reason string <optional>
Reason for editing this webhook
Source:
Returns:
Type
Promise.<Webhook>

send(contentopt, optionsopt) → {Promise.<(Message|Object)>}

Sends a message with this webhook.
Parameters:
Name Type Attributes Default Description
content StringResolvable | APIMessage <optional>
'' The content to send
options WebhookMessageOptions | MessageAdditions <optional>
{} The options to provide
Source:
Returns:
Type
Promise.<(Message|Object)>
Examples
// Send a basic message
webhook.send('hello!')
  .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('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(body) → {Promise.<boolean>}

Sends a raw slack message with this webhook.
Parameters:
Name Type Description
body Object The raw body to send
Source:
Returns:
Type
Promise.<boolean>
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() / 1000
  }]
}).catch(console.error);