Skip to main content

api

caution

All props/parameters are optional unless they are marked with an asterisk ( * ).

Props

NameTypeDescription
V6OrEarlierAPIErrorV6OrEarlierAPIErrorClass for creating API errors with v6 or earlier
V8APIErrorV8APIErrorClass for creating API errors with v8. Supports captcha and multiple errors.

Functions

NameParametersReturn TypeDescription
delete* req: string | HTTPRequest
callback: (response: HTTPResponse) => void
HTTPResponseFetch with DELETE method
get* req: string | HTTPRequest
callback: (response: HTTPResponse) => void
HTTPResponseFetch with GET method
getAPIBaseURLversion: booleanstringGets Discord's base API URL
patch* req: string | HTTPRequest
callback: (response: HTTPResponse) => void
HTTPResponseFetch with PATCH method
post* req: string | HTTPRequest
callback: (response: HTTPResponse) => void
HTTPResponseFetch with POST method
put* req: string | HTTPRequest
callback: (response: HTTPResponse) => void
HTTPResponseFetch with PUT method

Types

HTTPAttachment

NameTypeDescription
filestring | Blob | BufferFile path or binary data
filenamestringCustom file name
namestringField name in the request

HTTPField

NameTypeDescription
namestringField name
valuestringField value

HTTPRequest

NameTypeDefaultDescription
attachmentsHTTPAttachment[]Array containing data for an attachment
backoffBackoffBackoffUsed to retry a failed request after a specific time
binarybooleanfalseWhether to handle binary response bodies
bodyRecord<string, unknown>Body for the request
contextRecord<string, unknown>Object entries will be converted to JSON format and set to the X-Context-Properties header
fieldsHTTPField[]Array containing field data
headersRecord<string, string>Headers for the request
interceptResponse(response: Response, retry: (headers: Record<string, string>, interceptResponse: interceptResponse) => void, reject: (reason: Error) => void) => voidFunction ran to intercept the request response; check out superagent Response format
oldFormErrorsbooleanfalseWhether to use the old error handling
onRequestCreated(request: Request) => voidFunction ran at the start of the request; check out superagent Request format
onRequestProgress(progress: ProgressEvent) => voidFunction ran to track the progress of uploading or downloading files; check out superagent ProgressEvent format
querystring | Record<string, string>Request queries
reasonstringReason of the request set to the X-Audit-Log-Reason header
retriednumberHow many times the request failed and retried
retriesnumberHow many times the request can retry if failed
signalAbortSignalAbortSignal object
timeoutnumberSets a deadline in milliseconds for the request to complete and aborts if the request isn't completed in time
url* stringPath to fetch from (without the base API URL)

HTTPResponse

NameTypeDescription
bodystring | Record<string, unknown>Body contents
headersRecord<string, string>Headers associated with the response
okbooleanWhether the response was successful
statusnumberStatus code of the response
textstringHTTPResponse body in text