简体   繁体   中英

How to send a dm to another person discord.js? (javascript)

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.');
}

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 String s, so any id you use should be used as a string instead of a number like you have)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM