I cannout untimeout a user

const { MongoClient, ObjectId } = require('mongodb');
const findCase = require('./findcase.js')

// Connection URI
const uri = process.env.MONGO_URI;

// Create a new MongoClient
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

async function closeCase(caseId, caseType, instance) {
const foundCase = await findCase(caseId, caseType)

if (foundCase == null) {
return "CASENOTFOUND";
}
if (foundCase.closed) {
return "ALREADYCLOSED";
}

// Select the database and collection
const database = client.db('cases');
const collection = database.collection(caseType);

if (caseType == "mute") {
const guild = instance._client.guilds.cache.get(foundCase.guildId);
const userid = foundCase.user
const targetMember = guild.members.cache.get(userid)

console.log(guild.members)

targetMember.timeout(1)
}

const updatedCase = await collection.findOneAndUpdate(
{ _id: new ObjectId(caseId) },
{ $set: { closed: true, beingReviewed: false} },
{ returnOriginal: false } // Return the updated document
);

return "DONE";
}

// Export the findCaseById function to use it in other modules
module.exports = closeCase;
const { MongoClient, ObjectId } = require('mongodb');
const findCase = require('./findcase.js')

// Connection URI
const uri = process.env.MONGO_URI;

// Create a new MongoClient
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

async function closeCase(caseId, caseType, instance) {
const foundCase = await findCase(caseId, caseType)

if (foundCase == null) {
return "CASENOTFOUND";
}
if (foundCase.closed) {
return "ALREADYCLOSED";
}

// Select the database and collection
const database = client.db('cases');
const collection = database.collection(caseType);

if (caseType == "mute") {
const guild = instance._client.guilds.cache.get(foundCase.guildId);
const userid = foundCase.user
const targetMember = guild.members.cache.get(userid)

console.log(guild.members)

targetMember.timeout(1)
}

const updatedCase = await collection.findOneAndUpdate(
{ _id: new ObjectId(caseId) },
{ $set: { closed: true, beingReviewed: false} },
{ returnOriginal: false } // Return the updated document
);

return "DONE";
}

// Export the findCaseById function to use it in other modules
module.exports = closeCase;
12 Replies
d.js toolkit
d.js toolkit10mo 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!
lor3512
lor3512OP10mo ago
/Users/leo/Documents/DiscordBots/AussieArmyAssistant/utils/cases/closecase.js:31
targetMember.timeout(1)
^

TypeError: Cannot read properties of undefined (reading 'timeout')
at closeCase (/Users/leo/Documents/DiscordBots/AussieArmyAssistant/utils/cases/closecase.js:31:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async module.exports (/Users/leo/Documents/DiscordBots/AussieArmyAssistant/events/interactionCreate/closecasebutton.js:11:28)

Node.js v20.10.0
[nodemon] app crashed - waiting for file changes before starting...
/Users/leo/Documents/DiscordBots/AussieArmyAssistant/utils/cases/closecase.js:31
targetMember.timeout(1)
^

TypeError: Cannot read properties of undefined (reading 'timeout')
at closeCase (/Users/leo/Documents/DiscordBots/AussieArmyAssistant/utils/cases/closecase.js:31:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async module.exports (/Users/leo/Documents/DiscordBots/AussieArmyAssistant/events/interactionCreate/closecasebutton.js:11:28)

Node.js v20.10.0
[nodemon] app crashed - waiting for file changes before starting...
@ʎǝɹquoɯ Can you help?
monbrey
monbrey10mo ago
Can you read the rules
lor3512
lor3512OP10mo ago
Ah sry
ahmood
ahmood10mo ago
targetMember is undefined its better to fetch members using guild.members.fetch() as they arent always cached
lor3512
lor3512OP10mo ago
K Let me try that
darp
darp10mo ago
only if guild has more 75k members in that case discord wont send all members (only bot, and people in voice will returned) so i would use bot.rest.patch(Routes.guildMember(guildId, userId), {body: {communication_disabled_until: null}}) and never hope on cache
ahmood
ahmood10mo ago
oh yeah i meant fetch individual members using guild.members.fetch({ user: ... }), lmao should have been specific
lor3512
lor3512OP10mo ago
Ah k I got it possible by fetching by id, not using an object
duck
duck10mo ago
(This can also be achieved with <Guild>.members.edit())
darp
darp10mo ago
i always prefer using raw api than wrapper
duck
duck10mo ago
That's fine, but I'm just putting it out there since OP is using the wrapper that this server is for

Did you find this page helpful?