【问题标题】:DiscordAPIError: Cannot send messages to this user at RequestHandler.executeDiscordAPIError:无法在 RequestHandler.execute 向该用户发送消息
【发布时间】:2021-11-06 23:37:00
【问题描述】:

嘿,所以我在我的机器人中开了一个“hack”命令作为一个笑话,我希望它给消息的作者发送消息,但是每当我运行该命令时,它只会给我一个错误,即使作者已经打开DM的。这是错误:

DiscordAPIError:无法向该用户发送消息

这是我的代码:

msg.author.send(`Name:${taggedUser.username},
             ID:${taggedUser.id}
             IP Address:${response}`).catch(console.error)

        })
    })
})

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    除了会员对客户不可用或直接消息关闭之外,此特定错误不可能源自您可以简单地调整您的代码,因此如果 dms 已关闭,它将发布到频道而不是像所以:

    msg.author.send(`Name:${taggedUser.username},
                 ID:${taggedUser.id}
                 IP Address:${response}`).catch(() => {
        msg.channel.send(`Unable to Direct Message user instead sending this here!\n\n Name:${taggedUser.username},
                 ID:${taggedUser.id}
                 IP Address:${response}`)
        });
    

    来源:

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 2020-09-24
      • 2021-10-15
      • 2021-02-07
      • 2020-04-07
      • 2020-02-17
      • 2020-10-01
      • 2018-12-26
      相关资源
      最近更新 更多