【发布时间】:2021-08-11 23:40:57
【问题描述】:
我正在用 javascript 制作一个不和谐的机器人,并且我制作了一个将消息发送到特定频道的命令。它以前有效,但现在无效。我发现,问题出在这部分代码上:
let sugchannel = message.guild.channels.cache.find(c => c.name === "name");
sugchannel.send(embed).then((msg) =>{
message.delete();
}).catch((err)=>{
throw err;
});
我解决了很多类似的问题,但没有解决问题。此外,它确实有效,如果我将其更改为
message.channel.send(embed).then...
这是错误信息:
(node:416) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/runner/cutiefoxy/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (/home/runner/cutiefoxy/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
(node:416) 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:416) [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.
(node:416) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/runner/cutiefoxy/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (/home/runner/cutiefoxy/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
(node:416) 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: 2)
【问题讨论】:
-
在我看来,您的机器人只是缺少在您的服务器中执行该操作的权限。
-
它的权限和我一样。我是业主。这正是我感到困惑的原因。
-
你为什么在
throw err里面抓到? -
所问的问题是询问承诺以及拒绝处理程序如何工作。不过,我怀疑您可能想发布一个不同的问题,询问为什么
sugchannel.send(embed)失败并出现您在message.channel.send(embed)成功时显示的权限错误。
标签: javascript node.js promise discord.js