Home > Back-end >  How to send a dm to another person discord.js? (javascript)
How to send a dm to another person discord.js? (javascript)

Time:06-25

I'm making a discord bot and I wrote this code, but it gives an error, user.dm is not a function.

My code:

if(message.content.startsWith('s!modöner')) {
    let mesajöner = args.slice(1).join(' ');
    let userdm = 767387717792563241
    userdm.send(mesajöner);
    message.reply('Quixe Öneriniz Gönderildi.');
}

CodePudding user response:

I assume that the userdm variable is a user id, and you want to DM that user. In that case, you would first have to get the user from client.users.cache, then you can send it. An example:

const user = client.users.cache.get('767387717792563241')
user.send(mesajöner)

(Note: In discord, all ids are Strings, so any id you use should be used as a string instead of a number like you have)

  • Related