$olo
$olo
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
gud*
11 replies
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
lemme try
11 replies
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
thanks
11 replies
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
idk how to fetch the executor :sa_sad:
11 replies
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
i have the "MEMBER_ROLE_UPDATE" is not int
11 replies
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
here is my code
11 replies
DIAdiscord.js - Imagine an app
Created by $olo on 5/6/2024 in #djs-questions
working with audit logs ( problem with MEMBER_UPDATE")
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);
}
});
11 replies