Created
May 2, 2020 20:00
-
-
Save yuta0801/3d834df6c51592911137e44971682554 to your computer and use it in GitHub Desktop.
Complement stack trace of DiscordAPIError in Discord.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require('discord.js') | |
const client = new Discord.Client() | |
{ | |
const prototype = Object.getPrototypeOf(client.rest) | |
const original = Object.getOwnPropertyDescriptor(prototype, 'api').get | |
Object.defineProperty(prototype, 'api', { | |
get() { | |
const builder = original.apply(this) | |
return new Proxy(builder, { | |
get(target, name) { | |
const result = Reflect.get(target, name) | |
if (result.inspect) return new Proxy(result, this) | |
return (...args) => result(...args).catch(err => { | |
Error.captureStackTrace(err) | |
throw err | |
}) | |
}, | |
apply(target, _, args) { | |
return new Proxy(Reflect.apply(target, _, args), this) | |
} | |
}) | |
} | |
}) | |
} | |
client.on('message', () => { | |
handler().catch(err => console.error(err)) | |
}) | |
client.login() | |
const handler = async () => { | |
if (true) await command() | |
} | |
const command = async () => { | |
await client.channels.cache.get('706188750354645073').delete() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DiscordAPIError: Missing Permissions | |
at /index.js:16:19 | |
at processTicksAndRejections (internal/process/task_queues.js:97:5) | |
at async command (/index.js:39:3) | |
at async handler (/index.js:35:13) { | |
method: 'delete', | |
path: '/channels/706188750354645073', | |
code: 50013, | |
httpStatus: 403 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref discordjs/discord.js#2496