OceanicJS/Oceanic

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

Closed this issue · 1 comments

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.

For reference, the translated stack trace

archiveTimestamp: new Date(data.thread_metadata.archive_timestamp),


item = this.add(new this.#baseObject(value as M, this.#client, ...extra));

channel.threads.update(thread as never);

item = this.add(new this.#baseObject(value as M, this.#client, ...extra));

const guild = this.client.guilds.update(data);

const guild = this.createGuild(packet.d);

case GatewayOPCodes.DISPATCH: { void this.onDispatch(packet); break;

return this.onPacket(Erlpack.unpack(data) as AnyReceivePacket);