N
N
Nikita NeVajno2019-11-19 00:12:09
JavaScript
Nikita NeVajno, 2019-11-19 00:12:09

(node:17032) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'database' of undefined?

Hi
Trying to do "ban" commands for a bot
but it gives an error

spoiler
"(node:17032) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'database' of undefined"

I don’t understand at all what’s the matter.
Here is the ban code
spoiler
module.exports = {
    name: "ban",
    usage: "ban <user>",
    async execute(message, args , bot) {
        const target = message.mentions.users.first() ? message.mentions.users.first().id : args[2];
        await bot.database.ban(target, "user", "Admin ban");
        bot.banCache.user.push(target);
        message.channel.send(`<@${target}> has been banned!`);
    }
};

I'm new to this, please help. No need, and no one will provide a working code.
Please explain in the simplest language (for stupid (me)) that you can.
I don’t need to say that database is undefined during this period either, the problem is in the code, but I don’t understand where.
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Joker, 2019-11-19
@Pangsit

This means that the bot argument does not have a database property in the execute callback.
In addition, the callback is executed without an exception handler.
First you need to find out what the bot argument contains in the server console.

module.exports = {
    name: "ban",
    usage: "ban <user>",
    async execute(message, args , bot) {
        console.log("ban", bot);
        const target = message.mentions.users.first() ? message.mentions.users.first().id : args[2];
        await bot.database.ban(target, "user", "Admin ban");
        bot.banCache.user.push(target);
        message.channel.send(`<@${target}> has been banned!`);
    }
};

V
Vladimir, 2019-11-19
@HistoryART

The problem is that you are passing it into the function when you call it. This parameter does not have a database property.
Let's say you pass the object { x1=0, x2=1,x3=2}
The script tries to find database here, and then apply the ban () method.
It does not find it and throws an error saying that there is no such property.
Show the code of what you are passing - otherwise we will not go further than the analysis above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question