森林海
2021-08-26 16:07:06
我編寫了讓機器人向用戶發(fā)送私人消息的代碼,我需要知道用戶是否阻止了機器人或未能向他發(fā)送消息。這是我嘗試過的。如果失敗,我不希望機器人在下面發(fā)送消息:消息已發(fā)送!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 ?`) });}
2 回答

婷婷同學(xué)_
TA貢獻1844條經(jīng)驗 獲得超8個贊
將函數(shù)傳入then().
// Keep in mind that 'user' is a GuildMember the way it's been defined, not a User.
user.send(myMessage)
.then(() => message.channel.send(':incoming_envelope: Message sent successfully!'))
.catch(err => {
console.error(`Error while sending message to ${user.displayName}...\n`, err);
message.channel.send(':x: Message could not be sent.')
.catch(err => console.error(`Error while sending error message...\n`, err));
});
添加回答
舉報
0/150
提交
取消