[英]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.