【问题标题】:DM'ing a specific user IDDM 特定用户 ID
【发布时间】:2020-07-20 19:20:29
【问题描述】:
const Discord = require('discord.js');
const bot = new Discord.Client();
const PREFIX = "!!";

bot.on("message", async message => {
  if(message.content.toLowerCase().startsWith(`${PREFIX}suggest`)) {
     //a user says "!!suggest more commands"
     message. /*ID <@206377170707152906>*/ .send(`The user {$message.author.name.toString()} has given a suggestion; "${message.content.toString()}`);
     //then a DM is sent to the <@206377170707152906> ID saying (the ID is different from user ABC123's ID) "The user ABC123 has given a suggestion; "!!suggest more commands"
     message.author.send(`The suggestion "${message.content.toString()}" has been sent!`);
     return;
   }}

如何将ID“”放入message.send,以便将DM发送到“”ID?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    要发送直接消息,您需要用户对象。您可以从client.users 获取缓存的用户,但该用户可能不在缓存中。要“加载”该用户并向他发送消息,您可以执行以下操作:

    client.users.fetch('123456789').then((user) => {
        user.send("My Message");
    });
    

    不要忘记将123456789 替换为您想要的ID。在这种情况下,您只需要数字,不需要&lt;@...&gt;

    【讨论】:

    • 我有 '401: Unauthorized', /api/v7/users/:userId
    猜你喜欢
    • 2021-10-26
    • 2021-12-24
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 2021-04-26
    • 2018-05-10
    • 2021-11-21
    • 2020-08-20
    相关资源
    最近更新 更多