我如何摆脱message.delete(); DMS中的错误消息?

时间:2020-08-26 03:25:24

标签: javascript node.js discord.js

好吧,基本上我在机器人上的所有命令中都添加了message.delete();,因为我想删除作者对命令的请求。

一切都很好,但是当我DM机器人说出一条命令时,由于他无法删除该消息,将出现一条错误消息。

    at RequestHandler.execute (c:\Users\Pascale\Desktop\DungeonBot\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
<node_internals>/internal/process/warning.js:32
(node:17772) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
<node_internals>/internal/process/warning.js:32
(node:17772) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我该如何做,以便它返回并且没有错误消息出现??

1 个答案:

答案 0 :(得分:0)

有几种方法可以解决此问题。第一个是该机器人会在DM中忽略您以避免出现错误:

// detects if the message is sent in dms, returns if so
if (message.channel.type === 'dm') return;

我建议第一种解决方案,尽管第二种方法是使用try / catch块:

try {
 message.delete();
} catch {
 return;
}