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“&lt; @ 206377170707152906&gt;”进入message.send以便DM被发送到“&lt; @ 206377170707152906&gt;” ID?
答案 0 :(得分:2)
要发送直接消息,您需要用户对象。您可以从<shoppingcart>
<producttable>
<row number="0">
<productid>22804</productid>
<productname>XFree86 CD</productname>
<quantity>1</quantity>
<productprice>$15.00</productprice>
<discount>$0.00</discount>
<rowtotal>$15.00</rowtotal>
</row>
<row number="1">
<productid>193</productid>
<productname>Testproduct - Remote Key Generator</productname>
<quantity>1</quantity>
<productprice>$0.99</productprice>
<discount>$0.50</discount>
<rowtotal>$0.49</rowtotal>
</row>
</producttable>
</shoppingcart>
获取缓存用户,但用户可能不在缓存中。要“加载”该用户并向他发送消息,您可以执行以下操作:
client.users
不要忘记将client.fetchUser('123456789').then((user) => {
user.send("My Message");
});
替换为您想要的ID。在这种情况下,您只需要数字,不需要123456789