williamhorning / bolt

a cross-platform chat bot connecting your communities
MIT License
35 stars 3 forks source link

bolt-discord crashes due to disallowed intents #37

Closed williamhorning closed 1 year ago

williamhorning commented 1 year ago

bolt-discord fails to connect to discord, throwing an uncaught error. Looking at the part of WebSocketShard#onClose mentioned in the stack trace[^3][^4], it appears that bolt-discord is requesting disallowed intents when connecting to Discord. These aren't the same set of intents that we've used on djs13 but they still cover a lot more stuff than they should. Prod bot requests all of the privileged intents and that includes stuff that it shouldn't. Taking a look at the Discord API docs, it seems we only need to request the Guilds, GuildMessages, and MessageContent intents

bolt-bolt-1   | error: Uncaught (in promise) Error: Unhandled 'error' event emitted, received [object Object]
bolt-bolt-1   |     at WebSocketManager.emit (file:///deno-dir/npm/registry.npmjs.org/@vladfrangu/async_event_emitter/2.2.2/dist/index.mjs:250:19)
bolt-bolt-1   |     at WebSocketShard.<anonymous> (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.0.0/dist/index.mjs:1136:51)
bolt-bolt-1   |     at WebSocketShard.emit (file:///deno-dir/npm/registry.npmjs.org/@vladfrangu/async_event_emitter/2.2.2/dist/index.mjs:267:37)
bolt-bolt-1   |     at WebSocketShard.onClose (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.0.0/dist/index.mjs:1094:14)
bolt-bolt-1   |     at WebSocket.connection.onclose (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.0.0/dist/index.mjs:639:17)
bolt-bolt-1   |     at callListener (file:///deno-dir/npm/registry.npmjs.org/ws/8.13.0/lib/event-target.js:290:14)
bolt-bolt-1   |     at WebSocket.onClose (file:///deno-dir/npm/registry.npmjs.org/ws/8.13.0/lib/event-target.js:220:9)
bolt-bolt-1   |     at WebSocket.emit (ext:deno_node/_events.mjs:382:28)
bolt-bolt-1   |     at WebSocket.emitClose (file:///deno-dir/npm/registry.npmjs.org/ws/8.13.0/lib/websocket.js:258:10)
bolt-bolt-1   |     at Socket.socketOnClose (file:///deno-dir/npm/registry.npmjs.org/ws/8.13.0/lib/websocket.js:1264:15)

[^3]: https://cdn.jsdelivr.net/npm/@discordjs/ws@1.0.0/dist/index.mjs at line 1093 [^4]: While the error is annoying to read, that's out of scope for this issue and should be filed against djs