Discord.js无法向该用户发送消息

时间:2020-06-12 05:34:47

标签: javascript discord.js

如果出现此错误,它将发送一条嵌入消息,并显示有关如何打开直接消息的图片。

但是我不知道如何截断代码并发送此消息

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/node/src/index.ts",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "preLaunchTask": "build",
      "outFiles": [
        "${workspaceFolder}/node/dist/**/*.js"
      ]
    },
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ],
  "tasks": [
    {
      "label": "build",
      "type": "npm",
      "script": "yarn build"
    }
  ]
}

错误源

if (error.code === 50007){
  message.channel.send(Embedcantchat);
}

2 个答案:

答案 0 :(得分:0)

用户可能已关闭特定服务器的DM,因此该服务器中的成员将无法对其进行DM。您可以在点击服务器名称->隐私设置

时进行设置

答案 1 :(得分:0)

您应该尝试使用try / catch,而不是尝试通过错误代码发送消息,例如:

try {
   // message to send the user
}
catch (error) {
   message.channel.send(Embedcantchat);
   // other error handling
}

如果在尝试发送消息时发现错误,则假定已定义,它将自动发送Embedcantchat