Sending private messages to user

后端 未结 8 1540
清歌不尽
清歌不尽 2020-12-14 18:39

I\'m using the discord.js library and node.js to create a Discord bot that facilitates poker. It is functional except the hands are shown to everyone, and I need to loop thr

8条回答
  •  甜味超标
    2020-12-14 19:24

    To send a message to a user you first need a User instance representing the user you want to send the message to.


    Obtaining a User instance

    • You can obtain a User instance from a message the user sent by doing message.autor
    • You can obtain a User instance from a user id with client.fetchUser

    Once you got a user instance you can send the message with .send

    Examples

    client.on('message', (msg) => {
     if (!msg.author.bot) msg.author.send('ok ' + msg.author.id);
    });
    
    client.fetchUser('487904509670337509', false).then((user) => {
     user.send('heloo');
    });
    

提交回复
热议问题