working with audit logs ( problem with MEMBER_UPDATE")

i'm stuck since 2h trying to fix this .. xd #v14.14.1
4 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
$olo
$oloOP8mo ago
client.on('guildMemberUpdate', async (oldMember, newMember) => {
try {
setTimeout(async () => {
const fetchedLogs = await newMember.guild.fetchAuditLogs({
type: 'MEMBER_ROLE_UPDATE',
limit: 1
});
const auditLog = fetchedLogs.entries.first();
if (!auditLog) return;

const { executor, target } = auditLog;
if (!executor || !target || target.id !== newMember.id) return;

const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));
addedRoles.forEach(async role => {
const roleLimit = await getRoleLimitFromDatabase(role.id);
if (!roleLimit) return;

if (role.members.size > roleLimit.limitnumber) {
const isOwnerUser = await isOwner(newMember.id);
const isWhitelisted = await isUserInDatabase(newMember.id, 'whitelist', true);
const isBuyer = roleLimit.isbuyer;

if (!(isOwnerUser || isWhitelisted || isBuyer)) {
// verification of the executor's identity
const executorIsOwner = await isOwner(executor.id);
const executorIsWhitelisted = await isUserInDatabase(executor.id, 'whitelist', true);
const executorIsBuyer = executor.id === buyerID;

if (!(executorIsOwner || executorIsWhitelisted || executorIsBuyer)) {
try {
await newMember.roles.remove(role.id);
console.log(`Rôle "${role.name}" retiré à ${newMember.user.tag} car la limite a été atteinte.`);
} catch (error) {
console.error(`Erreur lors du retrait du rôle "${role.name}" à ${newMember.user.tag}:`, error);
}
}
}
}
});
}, 1000);
} catch (error) {
console.error('Erreur lors de la récupération des journaux d\'audit :', error);
}
});
client.on('guildMemberUpdate', async (oldMember, newMember) => {
try {
setTimeout(async () => {
const fetchedLogs = await newMember.guild.fetchAuditLogs({
type: 'MEMBER_ROLE_UPDATE',
limit: 1
});
const auditLog = fetchedLogs.entries.first();
if (!auditLog) return;

const { executor, target } = auditLog;
if (!executor || !target || target.id !== newMember.id) return;

const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));
addedRoles.forEach(async role => {
const roleLimit = await getRoleLimitFromDatabase(role.id);
if (!roleLimit) return;

if (role.members.size > roleLimit.limitnumber) {
const isOwnerUser = await isOwner(newMember.id);
const isWhitelisted = await isUserInDatabase(newMember.id, 'whitelist', true);
const isBuyer = roleLimit.isbuyer;

if (!(isOwnerUser || isWhitelisted || isBuyer)) {
// verification of the executor's identity
const executorIsOwner = await isOwner(executor.id);
const executorIsWhitelisted = await isUserInDatabase(executor.id, 'whitelist', true);
const executorIsBuyer = executor.id === buyerID;

if (!(executorIsOwner || executorIsWhitelisted || executorIsBuyer)) {
try {
await newMember.roles.remove(role.id);
console.log(`Rôle "${role.name}" retiré à ${newMember.user.tag} car la limite a été atteinte.`);
} catch (error) {
console.error(`Erreur lors du retrait du rôle "${role.name}" à ${newMember.user.tag}:`, error);
}
}
}
}
});
}, 1000);
} catch (error) {
console.error('Erreur lors de la récupération des journaux d\'audit :', error);
}
});
here is my code i have the "MEMBER_ROLE_UPDATE" is not int idk how to fetch the executor :sa_sad:
darp
darp8mo ago
$olo
$oloOP8mo ago
thanks lemme try gud*
Want results from more Discord servers?
Add your server