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

Error when removing role: TypeError [InvalidType]: Supplied user is not a UserResolvable. #8839

Closed
HassHz opened this issue Nov 16, 2022 · 4 comments

Comments

@HassHz
Copy link

HassHz commented Nov 16, 2022

Which package is this bug report for?

discord.js

Issue description

The following steps happen in a loop (around 8 runs max), and I get an error on the last step, sometimes for the first user, if that randomly ends up working, then fails on the second user, and so on. Believe it may be a caching issue, something related to this: #7474. If so, is there any workaround?

Steps run in a loop:

  1. Fetch Guild Member by ID
  2. Fetch / Create Roles
  3. Remove roles from member

Error:

TypeError [InvalidType]: Supplied user is not a UserResolvable.
    at GuildMemberManager.edit (.../node_modules/discord.js/src/managers/GuildMemberManager.js:294:20)
    at GuildMember.edit (.../node_modules/discord.js/src/structures/GuildMember.js:314:31)
    at GuildMemberRoleManager.set (.../node_modules/discord.js/src/managers/GuildMemberRoleManager.js:194:24)
    at GuildMemberRoleManager.remove (.../node_modules/discord.js/src/managers/GuildMemberRoleManager.js:157:19)
    at setNewRole (.../statUtils.js:21:29)
    at updateRoles (.../statUtils.js:44:15)
    at updateUsersRecord (.../statUtils.js:139:15)
    at async Object.execute (.../score.js:64:17)
    at async Client.<anonymous> (.../index.js:75:9) {
  code: 'InvalidType'
}

Code sample

for (const userID of userIDs) {
    const user = await message.guild.members.fetch(userID)

    const guildRoleCache = guild.roles.cache
    const role = guildRoleCache.find(role => role.name === 'role') || await guild.roles.create({ name: 'role', hoist: true })

    await user.roles.remove([role]) // Usually an array of roles
}

Package version

14.6.0

Node.js version

18.12.0

Operating system

MacOS, Ubuntu

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildMessages, GuildMessageReactions, MessageContent

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Jiralite commented Nov 16, 2022

Please include your full error. Never omit it!

Also, what is draftee?

@HassHz
Copy link
Author

HassHz commented Nov 16, 2022

Please include your full error. Never omit it!

Also, what is draftee?

Sorry updated, draftee was supposed to be user. For the users that it fails, if I print out the member object, the user field looks like this:

user: User {
    id: false,
    bot: false,
    system: false,
    flags: UserFlagsBitField { bitfield: 64 },
    username: '...', (omitted)
    discriminator: '...', (omitted)
    avatar: '...', (omitted)
    banner: undefined,
    accentColor: undefined
  }

@Jiralite
Copy link
Member

It seems the id is false. That seems impossible:

/**
* The user's id
* @type {Snowflake}
*/
this.id = data.id;

The only way this can happen is if you're mutating it. This seems to be an issue in your own code and not a library issue.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2022
@HassHz
Copy link
Author

HassHz commented Nov 17, 2022

It seems the id is false. That seems impossible:

/**
* The user's id
* @type {Snowflake}
*/
this.id = data.id;

The only way this can happen is if you're mutating it. This seems to be an issue in your own code and not a library issue.

For some reason it only seems to be happening for my user and the discord bot itself, have an idea of what could be going on? I don't believe I'm mutating it, can you give a sample of maybe some mutation?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants