bots - 涉及嵌入图像的 Discord.js 机器人错误
问题描述
因此,我编写了一个不和谐机器人,以根据命令从嵌入消息的文件夹中发送随机选择的 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.
解决方案
推荐阅读
- terraform - 基于另一个变量的引用变量
- python-3.x - ML 新手第一次尝试使用 SVM 和 SVR 出现一些语法/转置错误
- android - Xamarin Android 应用程序 504 错误
- ios - Flutter Podfile 和 Pods 文件夹未在 ios 目录中创建
- browser-cache - 谷歌页面速度见解上的浏览器缓存。谷歌如何对待私有缓存控制?
- visual-c++ - Visual C++ 看不到我的课程
- javascript - 如何使用 AWS Lambda (javascript) 下载大型 S3 文件
- python - 使用 Boost.Python 嵌入 Python 的 C++
- javascript - 使用 Jquery 使包含 iFrame 的外部 Div 可点击
- angular - 我想在我的欢迎组件上以角度 4 显示登录组件