member.setNickname or member.roles.add occasionally not working

Hi all, What reasons are there for a nickname potentially not being applied, or a role potentially not being applied? I have the following - which is fairly stock standard.
let aliveRole = RoleService.getRole(member.guild, "Alive");
if (!aliveRole) {
aliveRole = await RoleService.createRole(member.guild, { name: "Alive" });
}

await RoleService.addRole(member, aliveRole); // --> member.roles.add
const species = await SpeciesService.getSpecies(character.species);

const speciesRole = RoleService.getRole(member.guild, species.roleOptions.name);
await RoleService.addRole(member, speciesRole); // --> member.roles.add

if (member.user.id !== process.env.OWNER) {
//Only set nickname for non owner
await member.setNickname(character.name);
}
let aliveRole = RoleService.getRole(member.guild, "Alive");
if (!aliveRole) {
aliveRole = await RoleService.createRole(member.guild, { name: "Alive" });
}

await RoleService.addRole(member, aliveRole); // --> member.roles.add
const species = await SpeciesService.getSpecies(character.species);

const speciesRole = RoleService.getRole(member.guild, species.roleOptions.name);
await RoleService.addRole(member, speciesRole); // --> member.roles.add

if (member.user.id !== process.env.OWNER) {
//Only set nickname for non owner
await member.setNickname(character.name);
}
In some cases, the members nickname is not changed, or the alive role is not being added. (The species role seems to be correctly applied in every case). Usually, everything is applied correctly. I have not seen both the Alive role and the Nickname change not work. Most often - the nickname does not update.
I'm confused - because it seems sporadic. It's not a caching issue - the users display name is not changed on any client, even after refresh. To make things more confusing, the audit log appears to note the change - but the change does not appear to be applied. Am not getting and kind of error logs, the member object is defined (And other operations like those roles are working without issue)
5 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Bejasc
Bejasc3mo ago
Unsure whether this is something node process related... memory related... rate limit related... not sure where to look - because where I can look (based on the info I have) - I see no problems with
Spaxter
Spaxter3mo ago
Are you sure you're not being rate limited? How often are you performing these actions?
Morith
Morith3mo ago
Is it a role hierarchy issue? Trying to modify a user higher than the bot?
Bejasc
Bejasc3mo ago
definitely not this. Owner is the only permission higher, hence the check at all This is a good performance saving measure, I'll look into it thanks. I'm not sure - I'm definitely not getting anything back in logs that suggests that I am. These actions in particular are very infrequent. However, there are several frequent actions like bot sending messages