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?
9 Replies
d.js toolkit
d.js toolkit2w 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
SignGPTOP2w ago
node version: 22.9.0
Amgelo
Amgelo2w ago
- the member isn't in your cache, so your user variable is undefined - users aren't members (notice how you're using guild.members), so naming it user is a misnomer
d.js docs
d.js docs2w ago
Despite sounding similar there is a distinct difference between users and members in Discord: - User: global Discord user data (global avatar, username, tag, id) - GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.) - Conversion: User ➞ GuildMember | GuildMember ➞ User * Note: Events received in cached guilds will often have both the member and user available, eg. interaction.user and interaction.member
SignGPT
SignGPTOP2w ago
the member is a guild member
Amgelo
Amgelo2w ago
that doesn't mean they're on your cache djs doesn't cache all members by default, you'd have to do that manually somewhere before that code
SignGPT
SignGPTOP2w ago
ok thank you, how I can do it?
Amgelo
Amgelo2w ago
read this
SignGPT
SignGPTOP2w ago
ok
Want results from more Discord servers?
Add your server