thread.members.add is not a function

Hi can anyone help me with this code? code:
const { getThreadId } = require('../util/database/getThreadId.js');
const { claimTicket } = require('../util/database/claimTicket.js');

module.exports = {
async handleButton(interaction) {
if (interaction.customId.startsWith("claim")) {
const ticketNumber = interaction.customId.split("-")[1];
console.debug(`Ticket Number: ${ticketNumber}`);

const row = await getThreadId(ticketNumber);
const threadId = row ? row.threadId : null;

if (!threadId) {
console.error(`No thread ID found for ticket number: ${ticketNumber}`);
return;
}

// Prova a trovare il thread nella cache
let thread = interaction.channel.threads.cache.find(x => x.id === threadId);

// Se non trovato nella cache, prova a recuperarlo dall'API
if (!thread) {
try {
thread = await interaction.channel.threads.fetch(threadId);
console.log(thread)
} catch (error) {
console.error(`Failed to fetch thread with ID ${threadId}: ${error}`);
await interaction.reply({ content: `Impossibile trovare il thread associato al ticket.`, ephemeral: true });
return;
}
}

// Aggiungi l'utente al thread
try {
await thread.members.add(interaction.user.id);
await claimTicket(interaction.user.id, ticketNumber);
await interaction.reply({ content: `Hai reclamato con successo il ticket <#${ticketNumber}>.`, ephemeral: true });
} catch (error) {
console.error(`Failed to add user to thread or claim ticket: ${error.stack}`);
await interaction.reply({ content: `C'è stato un errore nel reclamare il ticket. Riprova più tardi.`, ephemeral: true });
}
}
}
}
const { getThreadId } = require('../util/database/getThreadId.js');
const { claimTicket } = require('../util/database/claimTicket.js');

module.exports = {
async handleButton(interaction) {
if (interaction.customId.startsWith("claim")) {
const ticketNumber = interaction.customId.split("-")[1];
console.debug(`Ticket Number: ${ticketNumber}`);

const row = await getThreadId(ticketNumber);
const threadId = row ? row.threadId : null;

if (!threadId) {
console.error(`No thread ID found for ticket number: ${ticketNumber}`);
return;
}

// Prova a trovare il thread nella cache
let thread = interaction.channel.threads.cache.find(x => x.id === threadId);

// Se non trovato nella cache, prova a recuperarlo dall'API
if (!thread) {
try {
thread = await interaction.channel.threads.fetch(threadId);
console.log(thread)
} catch (error) {
console.error(`Failed to fetch thread with ID ${threadId}: ${error}`);
await interaction.reply({ content: `Impossibile trovare il thread associato al ticket.`, ephemeral: true });
return;
}
}

// Aggiungi l'utente al thread
try {
await thread.members.add(interaction.user.id);
await claimTicket(interaction.user.id, ticketNumber);
await interaction.reply({ content: `Hai reclamato con successo il ticket <#${ticketNumber}>.`, ephemeral: true });
} catch (error) {
console.error(`Failed to add user to thread or claim ticket: ${error.stack}`);
await interaction.reply({ content: `C'è stato un errore nel reclamare il ticket. Riprova più tardi.`, ephemeral: true });
}
}
}
}
7 Replies
d.js toolkit
d.js toolkit3w 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
SignGPT
SignGPTOP3w ago
error:
Failed to add user to thread or claim ticket: TypeError: thread.members.add is not a function
at Object.handleButton (E:\0giochi-miei\Js\bot discord\imperyaTicket\buttons\claim.js:31:30)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Client.<anonymous> (E:\0giochi-miei\Js\bot discord\imperyaTicket\index.js:59:5)
Failed to add user to thread or claim ticket: TypeError: thread.members.add is not a function
at Object.handleButton (E:\0giochi-miei\Js\bot discord\imperyaTicket\buttons\claim.js:31:30)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Client.<anonymous> (E:\0giochi-miei\Js\bot discord\imperyaTicket\index.js:59:5)
d.js docs
d.js docs3w ago
:discord: Threads - Public & Private Threads read more
SignGPT
SignGPTOP3w ago
@Steve can you help me with this problem plesse? when I return to home I do that
d.js docs
d.js docs3w ago
:method: GuildTextThreadManager#fetch() @14.16.3 Obtains a thread from Discord, or the channel cache if it's already available.
// Fetch a thread by its id
channel.threads.fetch('831955138126104859')
.then(channel => console.log(channel.name))
.catch(console.error);
// Fetch a thread by its id
channel.threads.fetch('831955138126104859')
.then(channel => console.log(channel.name))
.catch(console.error);
- Discord ids follow the snowflake format: learn more - Discord ids must be represented as strings as they are larger than Number.MAX_SAFE_INTEGER, the largest integer that can be represented in JavaScript
- client.guilds.cache.get(123456789012345678)
+ client.guilds.cache.get("123456789012345678")
- client.guilds.cache.get(123456789012345678)
+ client.guilds.cache.get("123456789012345678")
SignGPT
SignGPTOP3w ago
ah ok @Qjuh thank you so much, i've resolved the problem
Want results from more Discord servers?
Add your server