TypeError: Function.prototype.apply was called on #<Object>, which is a object and not a function

1.1k Views Asked by At

I was working on a heist command for my bot but wehn i try it i get this error (node:2253) UnhandledPromiseRejectionWarning: TypeError: Function.prototype.apply was called on #<Object>, which is a object and not a function

My code is this and I dont know where it is coming from I wanted to make a heist command for my boy like dank memer.

const Discord = require('discord.js');
const db = require('quick.db')

module.exports.run = async (bot, message, args) => {
let member = message.mentions.members.first()
if (!member) return message.reply(`You you wanna hiest`)

let user = message.author;

let money = await db.fetch(`mon_${user.id}`)
if(money < 2000) return message.reply(`You need atleast 2000 coins to try and rob someone!`)

let money2 = await db.fetch(`b_${member.id}`)
if (money2 < 3000) return message.reply(`This fella does not have atleast 3000 coins in his bank not worth it!`)

message.channel.send(`${user.username} Is Starting a heist on ${member}\nType \`GG JOIN\` To join them!`).then(() => {
 message.channel.awaitMessages({ max: 7, time: 70000, errors: ['time'] })
    .then(message => {
       message = message.first()
       if (message.content.toUpperCase() == 'GG JOIN' || message.content.toUpperCase() == 'JOIN HEIST') {
         message.react("")
         db.fetch(`heistname_${message.guild.id}`)
         db.push(`heistname_${message.guild.id}`, -user.username)
         db.fetch(`heist_${message.guild.id}`)
         db.push(`heist_${message.guild.id}`, -user.id)
         db.fetch(`heistmem_${message.guild.id}`)
         db.add(`heistmem_${message.guild.id}`, 1)
       } else {
         return;
       }
     })
     .catch(collected => {
         message.channel.send('Allirght These Many Users Are joining the hesit.The Result will be given shortly!');
     });
 })
 setTimeout( async function() {
 let memjoined = await db.fetch(`heistmem_${message.guild.id}`)
let userbank = await db.fetch(`b_${member.id}`)
let bankdev = (userbank / memjoined)
let joined = await db.fetch(`heist_${message.guild.id}`)
let join2 = joined.split('-')
let jointot = join2.join('\n')
let joinname = await db.fetch(`heistname_${message.guild.id}`)
let joinnamesp = joinname.split('-')
let joinnametot = joinnamesp.join('\n')
db.add(`mon_${join2[0]}`, bankdev)
db.add(`mon_${join2[1]}`, bankdev)
db.add(`mon_${join2[2]}`, bankdev)
db.add(`mon_${join2[3]}`, bankdev)
db.add(`mon_${join2[4]}`, bankdev)
db.add(`mon_${join2[5]}`, bankdev)
db.add(`mon_${join2[6]}`, bankdev)
message.channel.send(`\`\`\`${joinnametot}Joined the heist and everyone came out with a total of ${bankdev} Money!\`\`\``)
}, 100000);

 setTimeout( async function(){
await db.delete(`heistmem_${message.guild.id}`)
await db.delete(`heistname_${message.guild.id}`)
await db.delete(`heist_${message.guild.id}`)
}, 10000);
}
module.exports.help = {
name: "bankrob",
aliases: ["heist"]
}
1

There are 1 best solutions below

0
On

The first parameter of TextChannel#awaitMessages should be a filter function, not an object. This filter function accesses the incoming message as a parameter, and decides whether to let it pass. A common use of this function is making sure the message author is the author of the original command:

message.channel.awaitMessages(
  (m) => m.author.id === message.author.id, 
  { /* options */ }
)

If you don't need any filter, you can just use () => true.