我编写了让机器人向用户发送私人消息的代码,我需要知道用户是否阻止了机器人或未能向他发送消息。
这是我尝试过的。如果失败,我不希望机器人在下面发送消息:
消息已发送!
if(message.content.startsWith(prefix+'send')){
if(!botOwner.includes(message.author.id)) return;
let userID = 'ID'; //to send
let channel = message.guild.channels.get(message.channel.id);
let user = bot.users.get(userID);
let myMessage = message.content.split(' ').slice(1).join(' ');
if(!myMessage) return;
user.send(myMessage)
.then(channel.send('Message Sent!')) //The problem in this line <-
.catch(err => {
console.error(err)
message.channel.send(`**${user.username}**, Failed to send him ❌`)
});
}
婷婷同学_
相关分类