Discord.js How to check if the user does not accept Direct Messages

不问归期 提交于 2020-06-25 05:35:10

问题


I was wondering if it is possible for a Discord bot to be able to check if a specific user the bot is trying to DM accepts direct messages. Right now this is my code:

exports.run = (client, message) => {
    try {
        message.author.send(`:ok_hand:`);
    } catch (err) {
        message.reply('Cannot send Direct Messages to your user!');
    }
}

But I want the code to be able to tell if the user is accepting direct messages before trying to send the user a message. Is this doable?


回答1:


Its not possible. The only way to find out if you can send a DM or not is try sending the message.
And instead of using try catch, you could use the catch from promises to catch the error and do something instead.

message.author.send('👌')
   .catch(() => message.reply("Can't send DM to your user!"));


来源:https://stackoverflow.com/questions/49621884/discord-js-how-to-check-if-the-user-does-not-accept-direct-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!