So I programmed a discord bot to, on command, send a randomly selected gif from a folder in an embedded message. It worked fine until I started trying to host the bot from Heroku. Now the command does nothing but displays an error in the log saying something like "could not find file extension", "deprecation error", or, just now, "unhandled promise rejection". My main issue is that I'm very new to programming in general, so I have no clue what exactly my problem is, let alone how to resolve it.
This is the current code I have for this particular section:
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;
Edit: as requested, here is the error message that appears:
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.
Related
I'm working with MongoDB to save data using transactions.But its giving the below error.
(node:29448) UnhandledPromiseRejectionWarning: MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession (D:\Rubix\rubixkyc\node_modules\mongoose\lib\connection.js:565:31)
at D:\Rubix\rubixkyc\server\util\route_utils.js:35:38
at new Promise (<anonymous>)
at saveKycData (D:\Rubix\rubixkyc\server\util\route_utils.js:32:12)
at D:\Rubix\rubixkyc\server\controllers\bulk_gst_verification_controller.js:48:19
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
[RUBIX KYC] 27-12-2022 07:44:37.193 PM [info]: <server\controllers\bulk_gst_verification_controller.js:46> saving GST verification data ....
(node:29448) MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession (D:\Rubix\rubixkyc\node_modules\mongoose\lib\connection.js:565:31)
at D:\Rubix\rubixkyc\server\util\route_utils.js:35:38
at new Promise (<anonymous>)
at saveKycData (D:\Rubix\rubixkyc\server\util\route_utils.js:32:12)
at D:\Rubix\rubixkyc\server\controllers\bulk_gst_verification_controller.js:48:19
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:29448) [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.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
Sharing the image of the code snippet.
Note:- This started happening after i started using worker pool for concurrency.
This save method i
const workerpool = require('workerpool');
Please help me with the issue
I have a problem : my bot won't delete the message after letting it go for 5 sec.
Here is my code :
client.on('message', message => {
if (message.content.toLowerCase().includes(",")) {
message.delete(); // You can put it here.
}
});
The error :
log (node:492) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.
at Message.delete (/home/runner/Boorubot-2/node_modules/discord.js/src/structures/Message.js:577:60)
at Client.<anonymous> (/home/runner/Boorubot-2/index.js:40:17)
at Client.emit (events.js:326:22)
at MessageCreateAction.handle (/home/runner/Boorubot-2/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/Boorubot-2/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/Boorubot-2/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/Boorubot-2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/Boorubot-2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/Boorubot-2/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:314:20)
(node:492) 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: 3)
When I run my app and someone in group left or new participant add to group, my bot stop working.
Below you can see code of my app:
const TelegramBot = require('node-telegram-bot-api');
const token = '1928095766:AAGf5aU7E1_FAM_fWzQs3SSGy-1AJS0DjcY';
const bot = new TelegramBot(token, { polling: true });
bot.on('message', async msg => {
const reg = /\d\d\-\d\d$/;
if (msg.text.match(reg)) {
bot.sendMessage(msg.chat.id, 'Gh')
}
})
And what I received in terminal if someone left group or new one add into, when my app is running:
(node:21155) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
at TelegramBot.<anonymous> (/Users/romansavka/Telegram-Bot-Node/telegram-bot/reminder.js:11:30)
at TelegramBot.emit (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/eventemitter3/index.js:182:35)
at TelegramBot.processUpdate (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:634:12)
at /Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:110:22
at Array.forEach (<anonymous>)
at /Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:106:17
at tryCatcher (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:462:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21155) 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:21155) [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.
It's because the message received has no attribute text, so the error raised UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
So basically I'm trying to send an announcement to specific channel using message.mentions.channels
ex !announce #announcements Today is a great day!
Error:
(node:5516) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channels' of undefined
at Object.module.exports.execute (C:\Users\Zarko\Desktop\Stackoverflow\commands\Answers\announce.js:3:36)
at Client.<anonymous> (C:\Users\Zarko\Desktop\Stackoverflow\events\message.js:20:30)
at Client.emit (events.js:223:5)
at MessageCreateAction.handle (C:\Users\Zarko\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
at WebSocket.onMessage (C:\Users\Zarko\node_modules\discord.js\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:223:5)
(node:5516) 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: 1)
(node:5516) [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.
Code:
let channel = message.mentions.channels.first();
if (!channel) return
let announcement = args.slice(1).join(" ");
channel.send(announcement)
Error was how you passed in variables:
in one of your other command files you had:
execute(client, message, args) {
//this works
}
And in your announce command file you had:
execute(message, args){
console.log(message, args);
/* =>
Client {
...
}
Message {
...
}
*/
}
So in this instance, message is the actual client object, and args is the actual message object, so simply just fix your variable spots,
Your new execute function in announce.js
execute(client, message, args) {
//rest of code here
}
I am trying to use chainpoint. I have a few hashes and am trying to submit them to chainpoint to create a timestamp proof and then anchor them to a public blockchain.
I am using the github tutorial https://github.com/chainpoint/chainpoint-js
But I am getting an error as
(node:8796) UnhandledPromiseRejectionWarning: Error: Argument must be
a non-empty Array
at S (C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:6002)
at H (C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:6533)
at de (C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:15276)
at Module. (C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:15596)
at tryCatch (C:\Users\Unmesha Banarjee\node_modules\regenerator-runtime\runtime.js:45:40)
at Generator.invoke [as _invoke] (C:\Users\Unmesha Banarjee\node_modules\regenerator-runtime\runtime.js:274:22)
at Generator.prototype.(anonymous function) [as next] (C:\Users\Unmesha
Banarjee\node_modules\regenerator-runtime\runtime.js:97:21)
at me (C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:15336)
at a (C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:16954)
at C:\Users\Unmesha Banarjee\node_modules\chainpoint-js\dist\bundle.js:1:17015 (node:8796)
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:8796) [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.
Can anyone help me...