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 toolkit4mo 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
cloud
cloudOP4mo 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 docs4mo ago
documentation suggestion for @Auth: :method: GuildMember#isCommunicationDisabled() @14.16.2 Whether this member is currently timed out
mallusrgreat
mallusrgreat4mo ago
use this instead
lupus
lupus4mo ago
You'd need Guilds/GuildMembers intent, but we can't really see your client definition.
cloud
cloudOP4mo ago
No description
cloud
cloudOP4mo ago
I do have intent Idk why event is not firing
lupus
lupus4mo ago
Are you actually registering the event somewhere?
cloud
cloudOP4mo ago
No description
cloud
cloudOP4mo ago
Line 170 It's working in another server Though I have given it admin in that server
lupus
lupus4mo ago
Are there any other notable differences?
cloud
cloudOP4mo 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
lupus4mo ago
Yeah, that makes sense in some way, but I'm not sure what perm guildmemberupdate is linked to.
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
cloud
cloudOP4mo ago
I believe that it does when someone manually removes it
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
cloud
cloudOP4mo ago
Emh Where exactly? + why is your pfp transparent
lupus
lupus4mo ago
Instead of checking whether communicationDisabledUntil is a false value. That function explicitly returns true/false without potentially guessing.
cloud
cloudOP4mo ago
Yeah but rn the function isn't getting called at all I'll make sure to implement that though
lupus
lupus4mo ago
Hmm, if you give the bot admin on the other server, does it start working?
cloud
cloudOP4mo ago
Yeah It does Then why tf it works in other server Lemme show how it works real quick
cloud
cloudOP4mo ago
:bidenW: now automodaction also aint working
cloud
cloudOP4mo ago
No description
cloud
cloudOP4mo 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