Skip to content

Webhook


Types


RatelimitInfo

RatelimitInfo.XRatelimitLimit : number?

RatelimitInfo.XRatelimitRemaining : number?

RatelimitInfo.XRatelimitReset : string?

RatelimitInfo.XRatelimitResetAfter : number?

RatelimitInfo.XRatelimitBucket : string?


Deprecation Notice

This type has been deprecated. Please use RatelimitInformation and RatelimitedInformation instead.



RatelimitInformation

Please use the offical Discord docs to reference what these values represent.

RatelimitInformation.limit : number

RatelimitInformation.remaining : number

RatelimitInformation.reset : string

RatelimitInformation.resetAfter : number (In seconds)

RatelimitInformation.resetAfterSafe : number (same as resetAfter, just with one extra second added)

RatelimitInformation.bucket : string

Info

The difference between RatelimitInformation and RatelimitedInformation is, RatelimitInformation is used to prevent getting ratelimited from the proxy, while RatelimitedInformation is used to handle a ratelimit responce from the proxy.

Warning

Logical errors must be avoided when handling bucket ratelimits yourself, as you may end up sending too many requests and getting either ratelimited or banned from the proxy.




RatelimitedInformation

Please use the offical Discord docs to reference what these values represent.

RatelimitedInformation.global : boolean

RatelimitedInformation.scope : string

RatelimitedInformation.retryAfter : number (In milliseconds)

RatelimitedInformation.retryAfterSafe : number (same as retryAfter, just with one extra second added)

Info

The difference between RatelimitInformation and RatelimitedInformation is, RatelimitInformation is used to prevent getting ratelimited from the proxy, while RatelimitedInformation is used to handle a ratelimit responce from the proxy.

Warning

Logical errors must be avoided when handling 429 responses yourself, as you may end up sending too many requests and getting banned from the proxy.




RequestStatus

RequestStatus.success : boolean

RequestStatus.statusCode : number

RequestStatus.statusMessage : string

RequestStatus.message : string?

RequestStatus.reason : string?




Properties


Webhook.id : string

The webhook's id.




Webhook.token : string

The webhook's token.

Danger

Never share this with anyone! If this string is made public it gives everyone full access to your webhook. If you think someone has your webhook's token the best course of action is to delete the webhook and create a new one.




Webhook.baseUrl : string

The webhook's base url.

Danger

Never share this with anyone! If this string is made public it gives everyone full access to your webhook. If you think someone has your webhook's url the best course of action is to delete the webhook and create a new one.




Webhook.ratelimitInfo : RatelimitInfo

The latest ratelimit information given to the webhook by Discord. Offical docs reference

Deprecation Notice

This property has been deprecated. Please use RatelimitInformation returned by :execute, :editMessage and :deleteMessage instead.

Note

ratelimitInfo will be nil until you make a request to Discord via :execute, :editMessage or :deleteMessage.

Tip

These values can be utilised to prevent getting ratelimited from the proxy.




Methods


Webhook.new(id : string, token : string, customProxyUrl : string?) : Webhook

This method returns a new Webhook object.

Parameters

  • id: The webhook's id.
  • token: The webhook's token.
  • customProxyUrl: The base url of a self hosted WebhookProxy. (example: "https://webhook.lewisakura.moe")




Webhook.fromUrl(webhookUrl : string, customProxyUrl : string?) : Webhook

This method returns a new Webhook object.

Note

The webhookUrl param should be a normal Discord webhook url.

Parameters

  • webhookUrl: The url of your webhook.
  • customProxyUrl: The base url of a self hosted WebhookProxy. (example: "https://webhook.lewisakura.moe")




Webhook:execute(content : string?, embeds : {[number] : Embed}?, queue : boolean, waitForMessage : boolean, optionalExecuteInfo : OptionalExecuteInfo?) : (Message? | ThreadMessage?, RequestStatus, RatelimitInformation | RatelimitedInformation | {})

This method sends a message to Discord.

Note

If both queue and waitForMessage are true, a message object will NOT be returned.

Note

If queue is left nil it will default to true. If waitForMessage is left nil it will default to false.

Note

If queue is true, ratelimitInfo will NOT be returned.

Tip

If you dont feel like making your own ratelimit handler set queue to true. This will ensure the message is sent to Discord. The only down side is it may take a few more seconds to be sent depending on how busy the proxy's queue is.

Parameters

  • content: The message's content.
  • embeds: A table of embeds that'll be attached to the message.
  • queue: Whether to queue the request, this will make sure the message is sent.
  • waitForMessage: Whether to wait for the message to be returned. If this is set to true a Message or ThreadMessage object will be returned depending on where the message was sent.
  • optionalExecuteInfo: Optional extra information for the request.




Webhook:editMessage(messageId : string, content : string?, embeds : {[number] : Embed}?, threadId : string?) : (EditedMessage | EditedThreadMessage, RequestStatus, RatelimitInformation | RatelimitedInformation)

This method edits a message sent by the webhook.

Parameters

  • messageId: The id of the message you wanna edit.
  • content: The new content that'll override the old content.
  • embeds: The new embeds that'll override the old embeds.
  • threadId: The id of the thread the message is in.




Webhook:deleteMessage(messageId : string, threadId : string?) : (RequestStatus, RatelimitInformation | RatelimitedInformation)

This method deletes a message sent by the webhook.

Parameters

  • messageId: The id of the message you wanna delete.
  • threadId: The id of the thread the message is in.




Webhook:_validateExecuteRequest(content : string?, embeds : {[number] : Embed}?, optionalExecuteInfo : OptionalExecuteInfo?) : (boolean, string?)

This method validates data given to :execute before sending it to the proxy. This is done to avoid making pointless requests to the proxy.

Warning

This method is not meant to be used outside Voyager's internal code.

Parameters

  • content: The content of the message.
  • embeds: A table of Embed objects.
  • optionalExecuteInfo: A OptionalExecuteInfo object.




Webhook:_validateEditMessageRequest(content : string?, embeds : {[number] : Embed}?) : (boolean, string?)

This method validates data given to :editMessage before sending it to the proxy. This is done to avoid making pointless requests to the proxy.

Warning

This method is not meant to be used outside Voyager's internal code.

Parameters

  • content: The content of the execute request.
  • embeds: The embeds of the execute request.




Webhook:_request(url : string, method : string, body : {}?, contentType : string) : ({}?, RequestStatus, RatelimitInformation | RatelimitedInformation | { })

This method is used to make HTTP requests to the proxy. While this method is not meant to be used outside Voyager's internal code, if you know what you're doing, it can be used to send requests to endpoints not yet implemented to Voyager yet.

Warning

This method is not meant to be used outside Voyager's internal code.

Parameters

  • url: The url the request will be sent to.
  • method: The HTTP method needed to make the request.
  • body: The body of the request.
  • contentType: The content type to use in the request header.