Webhook
Types
RatelimitInfo
RatelimitInfo.XRatelimitLimit : number?
RatelimitInfo.XRatelimitRemaining : number?
RatelimitInfo.XRatelimitReset : string?
RatelimitInfo.XRatelimitResetAfter : number?
RatelimitInfo.XRatelimitBucket : string?
RequestStatus
RequestStatus.success : boolean
RequestStatus.statusCode : number
RequestStatus.statusMessage : string
Properties
Webhook.id : string
The webhook's id.
Webhook.token : string
The webhook's token.
Danger
Never share this with anyone! If this value is made public all a malicious actor needs is your webhook's id which can be easily retrieved. Then you are at their mercy.
Webhook.baseUrl : string
The webhook's base url.
Danger
Never share this with anyone! If this value is made public it gives everyone with access to the value full access to your webhook. Then you are at their mercy. If you think someone has your webhook's url the best course of action is to delete it and create a new one.
Webhook.ratelimitInfo : RatelimitInfo
The latest ratelimit information given to the webhook by Discord. Offical docs reference
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.
Webhook:execute(content : string?, embeds : {[number] : Embed}?, queue : boolean, waitForMessage : boolean, optionalExecuteInfo : OptionalExecuteInfo?) : (Message? | ThreadMessage?, RequestStatus)
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.
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)
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
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)
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.