Home > Enterprise >  commandFetch.includes is not a function, but its in a array
commandFetch.includes is not a function, but its in a array

Time:02-27

i have a toggle system for commands but in the message event file, once i try to disable a command, the command is disabled but when i try the command again it comes up with the error:

TypeError: commandFetch.includes is not a function
    at module.exports (D:\D_Bots\D3V1L\events\guild\message.js:71:29)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

This is the code:

        let args = message.content.slice(prefix.length).trim().split(/  /g);
        const cmd = args.shift().toLowerCase();

        let commandfile = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd))
        if (commandfile) {
            let commandFetch = db.fetch(`commandToggle_${message.guild.id}`)
            if(commandFetch == null) commandFetch = []
            if(commandFetch.includes(commandfile.name)) return message.channel.send("This command is disabled")
            commandfile.run(client, message, args)

        }

Help would be appriciated, thanks

CodePudding user response:

It seems your db.fetch() method returning "Promise" so you need to "await" for response.

let commandFetch = await db.fetch(`commandToggle_${message.guild.id}`)

Something like that would be a solution for your problem.

CodePudding user response:

nvm, i found the problem, in my toggle command i did

db.push(`commandToggle_${message.guild.id}`, cmdName(args[0]))

it says args[0] but its meant to say args[1] after a few changes i got it to work

btw this is my first time actually asking a question on stack overflow, and i got a reply really fast, so thanks for your reply, i appriciate it

  • Related