Objects not getting pushed to collection.

const removed_roles = [];
if (added_roles && added_roles.length && previous_rankbind[0] > account_group_rank) {
previous_rankbind[1].roles.forEach(async (role_id) => {
if (member.roles.cache.find((member_role) => member_role.id == role_id) && !next_rankbind[1].roles.find((next_role_id) => next_role_id == role_id)) {
const rankbind_role = await guild.roles.fetch(role_id);

if (rankbind_role) {
await member.roles.remove(rankbind_role);

removed_roles.push(rankbind_role);

console.log(removed_roles); /** FULL COLLECTION */
console.log(removed_roles.length); /** 2 */
};
};
});
};

console.log(removed_roles); /** EMPTY COLLECTION */
console.log(removed_roles.length); /** 0 */
const removed_roles = [];
if (added_roles && added_roles.length && previous_rankbind[0] > account_group_rank) {
previous_rankbind[1].roles.forEach(async (role_id) => {
if (member.roles.cache.find((member_role) => member_role.id == role_id) && !next_rankbind[1].roles.find((next_role_id) => next_role_id == role_id)) {
const rankbind_role = await guild.roles.fetch(role_id);

if (rankbind_role) {
await member.roles.remove(rankbind_role);

removed_roles.push(rankbind_role);

console.log(removed_roles); /** FULL COLLECTION */
console.log(removed_roles.length); /** 2 */
};
};
});
};

console.log(removed_roles); /** EMPTY COLLECTION */
console.log(removed_roles.length); /** 0 */
This check will detect if a user's roles has been updated, and if they have their old position roles, then it gets removed. For example, detecting if an administrator demoted to a moderator still has the administrator role. I added the role that was removed to a collection so I can add it to an embed to send to the user, but the only problem is that the collection is always empty.
2 Replies
d.js toolkit
d.js toolkit8mo 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! - Marked as resolved by OP
aw0k3n
aw0k3nOP8mo ago
Never find, I fixed it. I had to use a for loop instead.
const removed_roles = [];
if (added_roles && added_roles.length && previous_rankbind[0] > account_group_rank) {
for (const role_id of previous_rankbind[1].roles) {
if (member.roles.cache.find((member_role) => member_role.id == role_id) && !next_rankbind[1].roles.find((next_role_id) => next_role_id == role_id)) {
const rankbind_role = await guild.roles.fetch(role_id);

if (rankbind_role) {
await member.roles.remove(rankbind_role);

removed_roles.push(rankbind_role);
};
};
}
};
const removed_roles = [];
if (added_roles && added_roles.length && previous_rankbind[0] > account_group_rank) {
for (const role_id of previous_rankbind[1].roles) {
if (member.roles.cache.find((member_role) => member_role.id == role_id) && !next_rankbind[1].roles.find((next_role_id) => next_role_id == role_id)) {
const rankbind_role = await guild.roles.fetch(role_id);

if (rankbind_role) {
await member.roles.remove(rankbind_role);

removed_roles.push(rankbind_role);
};
};
}
};
Want results from more Discord servers?
Add your server