繁体   English   中英

我无法向 discord.js 中的特定用户发送消息

[英]I can't send a message to a specific user in discord.js

我正在尝试制作一个在调用命令时向用户发送消息的系统。 但是每当我尝试时,它都会显示TypeError: Cannot read property 'send' of undefined.

这是我正在使用的代码。

 client.users.cache.get("220683253789163520").send("Test")

我正在使用 discord 版本 12。

这意味着在您需要使用<Client>.users.fetch方法获取用户之前,用户没有被缓存。

您的案例示例:

await client.users.fetch('220683253789163520');
client.users.cache.get('220683253789163520').send('Test');

使用Client.users.fetch()直接从API获取

const user = await client.users.fetch("220683253789163520")
await user.send("Test")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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