gpt4 book ai didi

javascript - DM'ing 一个特定的用户 ID

转载 作者:行者123 更新时间:2023-11-30 14:35:42 25 4
gpt4 key购买 nike

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“<@206377170707152906>”放入 message.send,以便将 DM 发送到“<@206377170707152906>”ID?

最佳答案

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

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

不要忘记用您想要的 ID 替换 123456789。在这种情况下,您只需要数字,不需要 <@...>

关于javascript - DM'ing 一个特定的用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50454266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com