Discord.Js-未捕获的DiscordAPIError:无法向该用户发送消息

时间:2020-10-24 19:20:41

标签: javascript discord discord.js bots

当我尝试使用DM中的漫游器回复用户时,出现以下错误:Discord.Js-Uncaught DiscordAPIError:无法向该用户发送消息

出什么问题了?

代码:

client.on('message', message=>{

    
    if(!message.author.send('$$')) return

    if(message.author.send('$$')){
        
        message.channel.send('Hi! Please describe your message to get help with it.').catch(error => {
            message.channel.send('I was unable to send a message.')
        })
    }

1 个答案:

答案 0 :(得分:1)

如果用户不接受不在他的朋友列表中的帐户的DM,被阻止等,则会返回此API错误。只需捕获该错误,一切便会按预期的方式运行-这不是错误,而是不和谐的API功能。

编辑:代码本身似乎也有问题,缺少一些括号:

client.on('message', message=> {

    if(message.author.bot) return;
    if(!message.author.send('$$')) return;

    if(message.author.send('$$')){
        
        message.channel.send('Hi! Please describe your message to get help with it.').catch(error => {
            message.channel.send('I was unable to send a message.')
        })
    }
})