Roles not adding correctly

  // Member is a GuildMember, passed from the interaction's interaction.member. i.e.:
  const member = interaction.member;
  // Example of rolesToAdd:
  const rolesToAdd = new Map([
    ['server id #1', new Set(['role id #1', ...])],
    ['server id #2', new Set(['role id #1', ...])],
  ]);
  for await (const [guildId, roleIds] of Object.entries(rolesToAdd)) {
    if (!roleIds.size) {
      container.logger.debug(`Skipped adding roles to user with id ${member.id} in guild with id ${guildId} as they already have them`);
      continue;
    }
    const guild = await container.client.guilds.fetch(guildId);
    if (!guild) {
      container.logger.warn(`Couldn't add roles to a user while syncing: guild with id ${guildId} not found.`);
      continue;
    }
    const guildMember = await guild.members.fetch(member.id);
    if (!guildMember) {
      container.logger.warn(`Couldn't add roles to a user while syncing: user with id ${member.id} not found in guild with id ${guildId}.`);
      continue;
    }
    await guildMember.roles.add([...roleIds], `[Sync] Adding staff role`)
      .catch((error) => {
        container.logger.warn(`Failed to add roles to user with id ${member.id} in guild with id ${guildId}:`, error);
      });
  }


Hi, I have this strange problem. If I run the command /sync in server #1, the roles are added correctly in server #1, however they are not added to server #2. The converse is also true. Could anyone help me out?
No errors. Using discord.js 14.15.3-dev.1715429013-7816ec2e6.
Was this page helpful?