createDiscordError
function in meocord/testing Since 4.1.0
createDiscordError(code: number, message?: string): DiscordAPIErrorCreates the error discord.js throws for a failed Discord API call, for a mock to reject with.
Use it to test what a handler or respond() does when Discord refuses a call. Common codes: 10062, the three
seconds to answer passed; 40060, already acknowledged; 50001, missing access; 50027, the fifteen-minute token
expired.
Parameters
| Name | Type | Description |
|---|---|---|
code | number | The Discord JSON error code. |
message? | string | The error's message; one naming the code by default. |
Returns
DiscordAPIErrorExamples
import { expect } from 'vitest'
const interaction = createMockInteraction(ChatInputCommandInteraction, { commandName: 'ping' })
interaction.reply.mockRejectedValueOnce(createDiscordError(10062))
// respond() passes Discord's refusal on to the handler, and a filter or the fallback answers it
await expect(respond(interaction).send('Pong!')).rejects.toMatchObject({ code: 10062 })