It works with "memes" and some other subreddits but not with "kungenavedsbyn". I'm probably really dumb but I can't figure out how to fix it.
bot.on('message', async msg => {
if (msg.content === '-örsk') {
let subreddits = [
"kungenavedsbyn"
];
let subreddit = subreddits[Math.floor(Math.random()*(subreddits.length))];
let img = await api(subreddit)
const Embed = new Discord.MessageEmbed()
.setTitle(`Här har du lite örsk`)
.setURL(`https://www.reddit.com/r/kungenavedsbyn`)
.setColor('RANDOM')
.setImage(img)
msg.channel.send(Embed)
}
});
Here's the message I get when I write the command in dc:
(node:11700) UnhandledPromiseRejectionWarning: err: [object Object]
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11700) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async functioch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/ap
(node:11700) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled
Related
I'm using tesseract within my node app. The first time the program runs fine.
In this example, foo() repeats it self. From the first repition on, an error is returned (shown below the code)
Could you give me a hint what I have done wrong which doesn't allow this to run a second time? I have tried to add try & catch, but it only led to more errors
const { createWorker } = require('tesseract.js');
const worker = createWorker();
function foo() {
(async () => {
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
await worker.setParameters({
tessedit_char_whitelist: '123456789'
// preserve_interword_spaces: '0',
});
const { data: { text } } = await worker.recognize('Download.png');
console.log(text);
await worker.terminate();
})();
setTimeout(foo, 10000);
}
foo();
Error message:
(node:13988) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
at module.exports (\\node_modules\tesseract.js\src\worker\node\send.js:9:10)
at \\node_modules\tesseract.js\src\createWorker.js:47:7
at new Promise (<anonymous>)
at startJob (\\node_modules\tesseract.js\src\createWorker.js:43:5)
at Object.load (\\node_modules\tesseract.js\src\createWorker.js:57:5)
at \\tesseract3.js:28:18
at Timeout.myFetch [as _onTimeout] (\\tesseract3.js:38:5)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13988) 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)
(node:13988) [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.
(node:13988) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
Learning MVC, I'm trying to seed my database with dummy entries and I keep getting this error:
(node:19287) UnhandledPromiseRejectionWarning: Error
at Query.run (/Users/joshuaramat/Documents/projects/tech-blog/node_modules/sequelize/lib/dialects/mysql/query.js:52:25)
at /Users/joshuaramat/Documents/projects/tech-blog/node_modules/sequelize/lib/sequelize.js:313:28
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async MySQLQueryInterface.bulkInsert (/Users/joshuaramat/Documents/projects/tech-blog/node_modules/sequelize/lib/dialects/abstract/query-interface.js:335:21)
at async recursiveBulkCreate (/Users/joshuaramat/Documents/projects/tech-blog/node_modules/sequelize/lib/model.js:1655:25)
at async Function.bulkCreate (/Users/joshuaramat/Documents/projects/tech-blog/node_modules/sequelize/lib/model.js:1744:12)
at async seedAll (/Users/joshuaramat/Documents/projects/tech-blog/seeds/index.js:14:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19287) 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:19287) [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.
the following is the code used to seed my data:
const seedUsers = require('./user-seeds');
const seedPosts = require('./post-seeds');
const seedComments = require('./comment-seeds');
const seedVotes = require('./vote-seeds');
const sequelize = require('../config/connection');
const seedAll = async () => {
await sequelize.sync({ force: true });
console.log('SEQUELIZE--------------');
await seedUsers();
console.log('USERS--------------');
await seedPosts();
console.log('POSTS--------------');
await seedComments();
console.log('COMMENTS--------------');
await seedVotes();
console.log('VOTES--------------');
process.exit(0);
};
seedAll();
The error seems to occur after the seedPosts() function is called.
Would anyone be able to help?
router.get('/:id', async (req, res) => {
const course = await Course.findById(req.params.id);
if (!course) {
return res.status(400).send(`course id is invaild`);
}
res.send(course);
});
As you guys can see, this is a very simple route function.
It works fine if it got the right id but once I gave it the wrong id it throws this error on my console
GET /api/courses/600f4aab118a6c5ef60fb5f7 200 75 - 20.069 ms
(node:32606) UnhandledPromiseRejectionWarning: CastError: Cast to
ObjectId failed for value "600f4aab118a6c5ef60fb5f7a" at path "_id"
for model "Course"
at model.Query.exec (/home/hesham/Desktop/test-express/node_modules/mongoose/lib/query.js:4358:21)
at model.Query.Query.then (/home/hesham/Desktop/test-express/node_modules/mongoose/lib/query.js:4452:15)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created) (node:32606)
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:32606) [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.
client.on("message", async (message) => { let roles = {
𝗢𝗪𝗡𝗘𝗥: "Owner",
ADMIN: "[ADM]",
Moderador: "[MOD]",
DcMod: "[DC]",
Booster: "[BOOST]",
Usuario: "[USER]"
}
let nombrerol = message.member.roles.cache.size <= 1 ? "Usuario" : message.member.roles.highest.name;
message.member.setNickname(`${roles[nombrerol]} ${message.author.username}`) })
and I get this error
(node:2604) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (E:\Bots\Skyliner[RP] Bots\XD\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (E:\Bots\Skyliner[RP] Bots\XD\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async GuildMember.edit (E:\Bots\Skyliner[RP] Bots\XD\node_modules\discord.js\src\structures\GuildMember.js:312:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2604) 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:2604) [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.
Means your bot does not have permissions to update the user's nickname. Try giving the bot those permissions and see what it does.
You'll need the MANAGE_NICKNAMES permission assigned to the bot, as per https://stackoverflow.com/a/49866239/1935718.
I'm making a discord bot and if I type $join into chat, I want the bot to join the voice channel that I'm in, and play a random sound.
case"join":
message.delete( {timeout: 5000})
const voiceChannel = message.member.voice.channel
if(voiceChannel) {
const connection = await voiceChannel.join()
const soundFile = fs.readFileSync("./sounds/")
const randFiles = soundFile[Math.floor(Math.random() * randFiles.length)]
const dispatcher = connection.play(randFiles)
} else {
message.reply("you need to be in a voice channel!").then(message => message.delete( {timeout: 5000}))
}
break;
I'm getting this error:
(node:13932) UnhandledPromiseRejectionWarning: Error: EISDIR: illegal operation on a directory, read
at Object.readSync (fs.js:524:3)
at tryReadSync (fs.js:349:20)
at Object.readFileSync (fs.js:386:19)
at Client.<anonymous> (C:\Users\PC\Desktop\doge_bot\doge-bot.js:124:38)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:13932) 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:13932) [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.
Have you read the documentation for readFileSync()? The only OS that readFileSync() successfully returns data on a directory path is on FreeBSD.
Instead, what it appears you're trying to do is grab a list of the files at a directory path; for this you could use fs.readdirSync():
const soundFile = fs.readdirSync("./sounds/")
fs.readFileSync("./sounds/") is for reading the contents of a file.
You're probably looking for fs.readdirSync("./sounds/") which gives you an array of files in a directory.