Answer the question
In order to leave comments, you need to log in
(node:17032) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'database' of undefined?
Hi
Trying to do "ban" commands for a bot
but it gives an error
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!`);
}
};
Answer the question
In order to leave comments, you need to log in
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!`);
}
};
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 questionAsk a Question
731 491 924 answers to any question