javascript - 使用 node.js 运行代码会出错,但没有 node 它可以完美运行
问题描述
我正在使用 Visual Studio 代码。当我正常运行我的代码时(CTRL+ALT+N),它运行良好。但是,当我使用 node.js 在 Windows Powershell 中运行它时,它给了我一个错误。这是我的代码:
if (message.content.startsWith(`${prefix}role`)) {
const filter = m => m.author.id === message.author.id;
message.delete(1);
message.reply("Choose title (message will expire after 10 seconds")
.then((r) => {
sleep(1)
botlastMSG = message.channel.lastMessageID
r.delete(10000)
})
message.channel.awaitMessages(filter, {max: 1, time: 10000, errors: ['time']}).then(collected => {
var response = collected.first().content
var respMsG = message.channel.lastMessageID
message.channel.fetchMessage(botlastMSG).then(msg => msg.delete(1));
if (response == "cancel") return message.channel.send("Cancelled!").then(r => r.delete(2000))
newArr.push(response)
show = 1
message.channel.fetchMessage(respMsG).then(msg => msg.delete(1))//deletes response
}).catch(err =>{message.reply("Time has expired!").then(r => r.delete(3000))})
while (show == 0) {
await sleep(1)
}
这是我在使用节点运行时遇到的错误:
(node:23652) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at item.request.gen.end (C:\Users\Adam\Desktop\botd\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15)
at then (C:\Users\Adam\Desktop\botd\node_modules\snekfetch\src\index.js:215:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:23652) 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(). (rejection id: 2)
(node:23652) [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.
解决方案
推荐阅读
- javascript - 使图像可拖动的问题
- typescript - 重叠类型的类型定义
- laravel - 如何将get var传递给后端?
- phaser-framework - 无法看到使用 Phaser 3.24.1 加载的图像
- java - 如何编写一个 junit 测试用例来获取文件并从 Amazon S3 存储桶中读取它
- android - 反应原生 || 使用 expo 更改屏幕方向
- android - 片段无法访问的自定义视图属性和函数(使用 DataBinding)
- c# - 如何在 C# 中检查日期是否超过 1 年?
- python-3.x - 为什么我不能从这个 pdf 中正确提取图像?[请需要帮助]
- docker - 如何指定容器将使用的 CPU 数量?