OceanicJS / Oceanic

A NodeJS library for interfacing with Discord.
https://oceanic.ws
MIT License
269 stars 25 forks source link

Announcement/public thread channels can sometimes cause GUILD_CREATE handler to fail #53

Closed TheEssem closed 1 year ago

TheEssem commented 1 year ago

I occasionally see this error pop up in logs when starting my bot. Running it standalone results in a crash, but running it in PM2 causes it to keep running after this:

TypeError: Cannot read properties of undefined (reading 'archive_timestamp')
    at new ThreadChannel (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/structures/ThreadChannel.js:46:61)
    at new AnnouncementThreadChannel (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/structures/AnnouncementThreadChannel.js:9:9)
    at Map.update (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/util/TypedCollection.js:54:29)
    at new Guild (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/structures/Guild.js:214:37)
    at Map.update (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/util/TypedCollection.js:54:29)
    at Shard.createGuild (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/gateway/Shard.js:146:42)
    at Shard.onDispatch (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/gateway/Shard.js:300:40)
    at Shard.onPacket (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/gateway/Shard.js:1044:27)
    at Shard.onWSMessage (/home/esmBot/esmBot/node_modules/.pnpm/oceanic.js@1.5.2-dev.df03c89_bufferutil@4.0.7/node_modules/oceanic.js/dist/lib/gateway/Shard.js:1229:29)
    at WebSocket.emit (node:events:513:28)

Since it seems to mostly occur on startup before the ready event, I'd imagine that it might be due to some missing/uncached data. After some attempts to debug the issue, it seems like a PublicThreadChannel is being passed into the data field of the ThreadChannel constructor. Will keep looking into this.

DonovanDMC commented 1 year ago

For reference, the translated stack trace https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/structures/ThreadChannel.ts#L66 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/structures/AnnouncementThreadChannel.ts#L13 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/util/TypedCollection.ts#L59 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/structures/Guild.ts#L308 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/util/TypedCollection.ts#L59 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/gateway/Shard.ts#L186 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/gateway/Shard.ts#L365 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/gateway/Shard.ts#L1184 https://github.com/OceanicJS/Oceanic/blob/df03c89b8562b694f9650cefb6084329f9853be9/lib/gateway/Shard.ts#L1385