Skip to content

TypeError: thread.members._add is not a function #10393

@JMTK

Description

@JMTK

Which package is this bug report for?

discord.js

Issue description

Creating this issue for posterity, bulk of the discussion and fix were noted here: https://discord.com/channels/222078108977594368/1248260322163294238

After a recent update to @discordjs/ws, it seems like Messages are being instantiated as channels in some very specific cases.

Full trace of the issue is here:

Trace
    at TextChannel._patch (/app/node_modules/discord.js/src/structures/TextChannel.js:15:15)
    at ChannelManager._add (/app/node_modules/discord.js/src/managers/ChannelManager.js:42:27)
    at MessageCreateAction.getPayload (/app/node_modules/discord.js/src/client/actions/Action.js:27:73)
    at MessageCreateAction.getChannel (/app/node_modules/discord.js/src/client/actions/Action.js:44:12)
    at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:9:26)
    at module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
    at WebSocketManager.<anonymous> (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
    at WebSocketManager.emit (/app/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:282:31)
    at WebSocketShard.<anonymous> (/app/node_modules/@discordjs/ws/dist/index.js:1190:51)

Sample "TextChannel" that is actually a "thread":

<ref *2> TextChannel {
  type: 0,
  guild: <ref *1> Guild {
    id: '755765126140919881',
    name: '彩虹研究社:rainbow:',
    icon: 'b2ea11110ab979ddda535b7c4479efc9',
    features: [
      'AUTO_MODERATION',
      'ROLE_ICONS',
      'SEVEN_DAY_THREAD_ARCHIVE',
      'ANIMATED_BANNER',
      'NEWS',
      'SOUNDBOARD',
      'BANNER',
      'ANIMATED_ICON',
      'INVITE_SPLASH',
      'CHANNEL_ICON_EMOJIS_GENERATED',
      'THREE_DAY_THREAD_ARCHIVE',
      'MEMBER_PROFILES',
      'COMMUNITY',
      'VANITY_URL',
      'PRIVATE_THREADS'
    ],
    (TRUNCATING SO I CAN PASTE IN DISCORD)
  },
  guildId: '755765126140919881',
  permissionOverwrites: PermissionOverwriteManager { channel: [Circular *2] },
  messages: GuildMessageManager { channel: [Circular *2] },
  threads: GuildTextThreadManager { channel: [Circular *2] },
  nsfw: false,
  flags: ChannelFlagsBitField { bitfield: 0 },
  id: '1262790110647156736',
  parentId: null,
  defaultThreadRateLimitPerUser: null,
  memberCount: 7,
  rawPosition: 4,
  lastMessageId: '1262806103016607784'
}

(Note the memberCount property here means we know it's a thread)

I think the possible problem commit was: #10278

Code sample

Not sure on exactly what the code sample is to reproduce this yet

Versions

  • discord.js v14.15.3
  • nodejs v21.7.1

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

User, Channel, GuildMember, Message, Reaction, ThreadMember

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildPresences, GuildMessages, DirectMessages

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions