代码:
if(command === "dm"){
console.log((chalk.yellow)`You ran a command: dm`)
const id = args[0]
const message = args.slice(1).join(" ")
let user = client.users.cache.get(id)
user.send(message)
}
错误:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
怎么了?我一直在使用这个完全相同的代码,但通道确实有效。顺便说一句,命令看起来像这样:-dm userIDhere messagehere
client.users.cache.get(id).send(message);
将工作
所以它看起来像:
console.log((chalk.yellow)`You ran a command: dm`);
const id = args[0];
const message = args.slice(1).join(" ");
client.users.cache.get(id).send(message)
};