SignGPT
SignGPT
DIAdiscord.js - Imagine an app
Created by SignGPT on 11/23/2024 in #djs-questions
Error while DM user
Cannot read properties of undefined (reading 'createDM')
at Object.execute (E:\0giochi-miei\Js\bot discord\imperyaTicket\commands\admin\close.js:96:34)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Client.<anonymous> (E:\0giochi-miei\Js\bot discord\imperyaTicket\index.js:75:9)
Cannot read properties of undefined (reading 'createDM')
at Object.execute (E:\0giochi-miei\Js\bot discord\imperyaTicket\commands\admin\close.js:96:34)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Client.<anonymous> (E:\0giochi-miei\Js\bot discord\imperyaTicket\index.js:75:9)
const user = interaction.guild.members.cache.get(userId);

const embedDmUser = new EmbedBuilder()
.setTitle('Ticket Chiuso')
.addFields(
{
name: "Staffer:",
value: `<@${interaction.user.id}>`
},
{
name: "Motivo:",
value: motivo
},
{
name: "Ticket ID:",
value: ticketNumber
}
)
.setDescription('Per eventuali reclami fornisci una motivazione valida aprendo un altro ticket.\n\n**N.B. Non condividiamo il transcript del ticket con gli utenti per motivi di privacy e riservatezza.**')
.setColor('Blue')
.setAuthor({ name: 'ImperyaMC - Assistenza', iconURL: 'https://i.imgur.com/uwr6GRs.png' })
.setThumbnail('https://i.imgur.com/uwr6GRs.png');

const dmChannel = await user.createDM();
await dmChannel.send({ embeds: [embedDmUser] })
const user = interaction.guild.members.cache.get(userId);

const embedDmUser = new EmbedBuilder()
.setTitle('Ticket Chiuso')
.addFields(
{
name: "Staffer:",
value: `<@${interaction.user.id}>`
},
{
name: "Motivo:",
value: motivo
},
{
name: "Ticket ID:",
value: ticketNumber
}
)
.setDescription('Per eventuali reclami fornisci una motivazione valida aprendo un altro ticket.\n\n**N.B. Non condividiamo il transcript del ticket con gli utenti per motivi di privacy e riservatezza.**')
.setColor('Blue')
.setAuthor({ name: 'ImperyaMC - Assistenza', iconURL: 'https://i.imgur.com/uwr6GRs.png' })
.setThumbnail('https://i.imgur.com/uwr6GRs.png');

const dmChannel = await user.createDM();
await dmChannel.send({ embeds: [embedDmUser] })
can anyone help me please?
11 replies
DIAdiscord.js - Imagine an app
Created by SignGPT on 11/18/2024 in #djs-questions
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 });
}
}
}
}
11 replies