Discord. js ошибок ботов, связанных со встроенными изображениями - PullRequest
1 голос
/ 11 июля 2020

Итак, я запрограммировал бота Discord, чтобы по команде отправлять случайно выбранный 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.
...