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