我正在尝试创建一个系统,在调用命令时向用户发送消息。但每当我尝试时,它都会显示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")