Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图对用户进行 dm,但我只有 id。这是我使用的代码:
const member = bot.users.cache.find(ID) member.send('TEXT')
它不工作。有谁知道为什么?
如果用户没有被缓存,你可以这样做。
const member = bot.users.fetch('user-id',false,true)
这有助于直接从 API 获取成员数据。更多在这里
就像其他人所说的那样,用户可能没有被缓存。据我所知,你对此无能为力。
如果您想避免undefined您遇到的错误,并捕获发送消息时可能发生的任何错误:
undefined
const member = bot.users.cache.find(ID); if (member) member.send('TEXT').catch(console.error);