Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exception when adding member that is already part of the guild #10337

Closed
toms opened this issue Jun 8, 2024 · 0 comments · Fixed by #10338
Closed

Uncaught exception when adding member that is already part of the guild #10337

toms opened this issue Jun 8, 2024 · 0 comments · Fixed by #10338

Comments

@toms
Copy link

toms commented Jun 8, 2024

Which package is this bug report for?

discord.js

Issue description

I am attempting to add a member to my guild that is already an existing member like so

const addOpts = { accessToken, roles: roleIds, fetchWhenExisting: false };
const guildMember = await guild.members.add(discordId, addOpts);
if (!guildMember) {
    const existingGuildMember = await guild.members.fetch({ user: discordId });
    // more logic
}

but am getting the following uncaught exception:

TypeError: Cannot read properties of undefined (reading 'id')
    at GuildMemberManager._add (/node_modules/discord.js/src/managers/GuildMemberManager.js:39:52)
    at GuildMemberManager.add (/node_modules/discord.js/src/managers/GuildMemberManager.js:139:14)

The issue seems to be in this section here in the add function:

const data = await this.client.rest.put(Routes.guildMember(this.guild.id, userId), { body: resolvedOptions });
// Data is an empty Uint8Array if the member is already part of the guild.
return data instanceof Uint8Array
    ? options.fetchWhenExisting === false
        ? null
        : this.fetch(userId)
    : this._add(data);

The comment indicates that the returned result should be a Uint8Array if the member is already in the guild, but I am getting an empty ArrayBuffer instead.
I added the following log statements:

console.log('data', data);
console.log('data instanceof Uint8Array', data instanceof Uint8Array);
console.log('data instanceof ArrayBuffer', data instanceof ArrayBuffer);

and got the following output:

data ArrayBuffer { [Uint8Contents]: <>, byteLength: 0 }
data instanceof Uint8Array false
data instanceof ArrayBuffer true

And I do not think it's an oauth/bot permission issue because I'm able to successfully add a member to the guild if they are not already a member.

Code sample

No response

Versions

  • discord.js - 14.12.1
  • node - v18.18.1

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers

I have tested this issue on a development release

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants