因此,我编写了一个discord bot,以根据命令从嵌入消息中的文件夹中发送随机选择的gif。在我开始尝试从Heroku托管该机器人之前,它一直运行良好。现在,该命令不执行任何操作,但在日志中显示错误,提示诸如“找不到文件扩展名”,“弃用错误”或刚才出现的“未处理的承诺拒绝”之类的错误。我的主要问题是,我通常对编程还是很陌生的,所以我不知道到底是什么问题,更不用说如何解决了。
这是该部分的当前代码:
case '//command':
const Embed = new MessageEmbed()
var number = 43;
var imageNumber = Math.floor (Math.random()*(number-1+1))+1
Embed.setTitle("//message")
Embed.setDescription("//message")
Embed.attachFiles({files: ["./images/" + imageNumber + ".gif"]})
Embed.setImage("attachment://" + imageNumber + ".gif")
Embed.setColor(0x9B00C3)
msg.channel.send(Embed)
break;
编辑:根据要求,以下是出现的错误消息:
2020-07-11T17:23:22.063132+00:00 app[web.1]: (node:23) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'path' of undefined
2020-07-11T17:23:22.063143+00:00 app[web.1]: at findName (/app/node_modules/discord.js/src/structures/APIMessage.js:273:17)
2020-07-11T17:23:22.063144+00:00 app[web.1]: at Function.resolveFile (/app/node_modules/discord.js/src/structures/APIMessage.js:289:31)
2020-07-11T17:23:22.063145+00:00 app[web.1]: at /app/node_modules/discord.js/src/structures/APIMessage.js:224:72
2020-07-11T17:23:22.063147+00:00 app[web.1]: at Array.map (<anonymous>)
2020-07-11T17:23:22.063147+00:00 app[web.1]: at APIMessage.resolveFiles (/app/node_modules/discord.js/src/structures/APIMessage.js:224:46)
2020-07-11T17:23:22.063148+00:00 app[web.1]: at TextChannel.send (/app/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:172:46)
2020-07-11T17:23:22.063149+00:00 app[web.1]: at Client.<anonymous> (/app/index.js:76:25)
2020-07-11T17:23:22.063149+00:00 app[web.1]: at Client.emit (events.js:315:20)
2020-07-11T17:23:22.063149+00:00 app[web.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-07-11T17:23:22.063150+00:00 app[web.1]: at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-07-11T17:23:22.063226+00:00 app[web.1]: (node:23) 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)
2020-07-11T17:23:22.063337+00:00 app[web.1]: (node:23) [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.