ApiError

class ApiError

A Discord API request that failed. SDK methods that call Discord throw this. Methods typed to return null return it for a 404 instead of throwing.

try {
  await member.ban();
} catch (error) {
  if (error instanceof discord.ApiError && error.status === 403) {
    await message.reply("I don't have permission to ban them.");
  } else {
    throw error;
  }
}
Extends:
  • Error

Properties

Property

Type

Description

code

number

Discord’s JSON error code, or 0 when Discord didn’t send one.

name

“ApiError”

retryAfter

number | null

Seconds to wait before retrying, for a 429 response. null otherwise.

status

number

HTTP status Discord answered with, such as 403 or 404.