which perms do i need

i have this event
client.on('guildMemberUpdate', async (oldMember, newMember) => {
await handleMemberUpdate(oldMember, newMember, clientId)
});
client.on('guildMemberUpdate', async (oldMember, newMember) => {
await handleMemberUpdate(oldMember, newMember, clientId)
});
but its not firing when i remove someones timeout
24 Replies
d.js toolkit
d.js toolkit2mo 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
Auth
AuthOP2mo ago
const {
AuditLogEvent
} = require('discord.js')

const {users} = require('../../models/User')
const db = require('../../db');
const { eq } = require('drizzle-orm');


async function handleMemberUpdate(oldMember, newMember, client) {
if (!oldMember.communicationDisabledUntil && newMember.communicationDisabledUntil) {
console.log(`${newMember.user.tag} was timed out until ${newMember.communicationDisabledUntil.toISOString()}`);

try {
const auditLogs = await newMember.guild.fetchAuditLogs({
type: AuditLogEvent.MemberUpdate,
limit: 1,
});

const timeoutLog = auditLogs.entries.first();
const moderator = timeoutLog ? timeoutLog.executor : null;

console.log(`Timeout moderator: ${moderator ? moderator.tag : 'AutoMod or Unknown'}`);

} catch (error) {
console.error('Error handling member timeout:', error);
}
}
// Check if the timeout has been removed
else if (oldMember.communicationDisabledUntil && !newMember.communicationDisabledUntil) {
const existingUser = await db.select({
userId: users.userId,
leetcode: users.leetcode,
time: users.time,
}).from(users).where(eq(users.userId, oldMember.user.id));

console.log(existingUser)

if(existingUser.length !== 0){
await db.delete(users).where(eq(users.userId, newMember.user.id));
console.log(`${newMember.user.tag} removed from db`)
}

console.log('user aint in db')

}
}

module.exports = {handleMemberUpdate}
const {
AuditLogEvent
} = require('discord.js')

const {users} = require('../../models/User')
const db = require('../../db');
const { eq } = require('drizzle-orm');


async function handleMemberUpdate(oldMember, newMember, client) {
if (!oldMember.communicationDisabledUntil && newMember.communicationDisabledUntil) {
console.log(`${newMember.user.tag} was timed out until ${newMember.communicationDisabledUntil.toISOString()}`);

try {
const auditLogs = await newMember.guild.fetchAuditLogs({
type: AuditLogEvent.MemberUpdate,
limit: 1,
});

const timeoutLog = auditLogs.entries.first();
const moderator = timeoutLog ? timeoutLog.executor : null;

console.log(`Timeout moderator: ${moderator ? moderator.tag : 'AutoMod or Unknown'}`);

} catch (error) {
console.error('Error handling member timeout:', error);
}
}
// Check if the timeout has been removed
else if (oldMember.communicationDisabledUntil && !newMember.communicationDisabledUntil) {
const existingUser = await db.select({
userId: users.userId,
leetcode: users.leetcode,
time: users.time,
}).from(users).where(eq(users.userId, oldMember.user.id));

console.log(existingUser)

if(existingUser.length !== 0){
await db.delete(users).where(eq(users.userId, newMember.user.id));
console.log(`${newMember.user.tag} removed from db`)
}

console.log('user aint in db')

}
}

module.exports = {handleMemberUpdate}
d.js docs
d.js docs2mo ago
documentation suggestion for @Auth: :method: GuildMember#isCommunicationDisabled() @14.16.2 Whether this member is currently timed out
mallusrgreat
mallusrgreat2mo ago
use this instead
lupus
lupus2mo ago
You'd need Guilds/GuildMembers intent, but we can't really see your client definition.
Auth
AuthOP2mo ago
No description
Auth
AuthOP2mo ago
I do have intent Idk why event is not firing
lupus
lupus2mo ago
Are you actually registering the event somewhere?
Auth
AuthOP2mo ago
No description
Auth
AuthOP2mo ago
Line 170 It's working in another server Though I have given it admin in that server
lupus
lupus2mo ago
Are there any other notable differences?
Auth
AuthOP2mo ago
Nah pretty sure the problem is somewhat related to perms Previously AutomoderationActionExecution Was also not firing But it got fixed with manage server permission
lupus
lupus2mo ago
Yeah, that makes sense in some way, but I'm not sure what perm guildmemberupdate is linked to.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Auth
AuthOP2mo ago
I believe that it does when someone manually removes it
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Auth
AuthOP2mo ago
Emh Where exactly? + why is your pfp transparent
lupus
lupus2mo ago
Instead of checking whether communicationDisabledUntil is a false value. That function explicitly returns true/false without potentially guessing.
Auth
AuthOP2mo ago
Yeah but rn the function isn't getting called at all I'll make sure to implement that though
lupus
lupus2mo ago
Hmm, if you give the bot admin on the other server, does it start working?
Auth
AuthOP2mo ago
Yeah It does Then why tf it works in other server Lemme show how it works real quick
Auth
AuthOP2mo ago
:bidenW: now automodaction also aint working
Auth
AuthOP2mo ago
No description
Auth
AuthOP2mo ago
Yeah it got fixed by changing the bot lmao But still it don't fires guild update event
Want results from more Discord servers?
Add your server