Click here to Skip to main content
15,918,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
const prefix = require('./models/prefix')
client.prefix = async function(message) {
    let custom;
    const data = await prefixSchema.findOne({ Guild : message.guild.id })
        .catch(err => console.log(err))  
    if(data) {
        custom = data.Prefix;
    } else {
        custom = prefix;
    }
    return custom;
  }
  client.on('message', async (message) => {
    if (message.author.bot) return;
    const data = await prefix.findOne({
        GuildID: message.guild.id
    });
    const messageArray = message.content.split(' ');
    const cmd = messageArray[0];
    const args = messageArray.slice(1);
    if(data) {
        const prefix = data.Prefix;
        if(message.mentions.users.first()) {
            const pingchannel = client.channels.cache.get('959866612675137576')
        if(message.mentions.users.first().id === '940712848349335612') return message.channel.send(`My prefix is **\`${prefix}\`**`), pingchannel.send(`${message.author.tag} pinged me`)
    }
        if (!message.content.startsWith(prefix)) return;
        const commandfile = client.commands.get(cmd.slice(prefix.length)) 
        if(!commandfile){
          //if (commandfile) {
            if(commandfile.timeout) {
                if(Timeout.has(`${commandfile.name}${message.author.id}`)) return message.channel.send(`You are on a \`${ms(Timeout.get(`${commandfile.name}${message.author.id}`) - Date.now(), {long : true})}\` cooldown.`)
                //commandfile.run(client, message, args)
                Timeout.set(`${commandfile.name}${message.author.id}`, Date.now() + commandfile.timeout)
                setTimeout(() => {
                    Timeout.delete(`${commandfile.name}${message.author.id}`)
                }, commandfile.timeout)
            }
        //}
        }
        commandfile.run(client, message, args).catch(console.error)
        const lchannel = client.channels.cache.get('959866612675137576')
        lchannel.send(`${message.author.tag} used ${commandfile.name} command`)
    } else if (!data) {
        const prefix = "!!";
        if(message.mentions.users.first()) {
            const pingchannel = client.channels.cache.get('959866612675137576')
          if(message.mentions.users.first().id === '940712848349335612') return message.channel.send(`My prefix is **\`!!\`**`), pingchannel.send(`${message.author.tag} pinged me`) 
        }
        if (!message.content.startsWith(prefix)) return;
        const commandfile = client.commands.get(cmd.slice(prefix.length)) 
        if(!commandfile){
          if (commandfile) {
            if(commandfile.timeout) {
                if(Timeout.has(`${commandfile.name}${message.author.id}`)) return message.channel.send(`You are on a \`${ms(Timeout.get(`${commandfile.name}${message.author.id}`) - Date.now(), {long : true})}\` cooldown.`)
                commandfile.run(client, message, args).catch(console.error)
                Timeout.set(`${commandfile.name}${message.author.id}`, Date.now() + commandfile.timeout)
                setTimeout(() => {
                    Timeout.delete(`${commandfile.name}${message.author.id}`)
                }, commandfile.timeout)
            }
        }
        }
        commandfile.run(client, message, args).catch(console.error)
        const lchannel = client.channels.cache.get('959866612675137576')
        lchannel.send(`${message.author.tag} used ${commandfile.name} command`)
    }
  })


What I have tried:

I have tried chaning the code but i ended up messing everything. I hope someone will help me with this problem
Posted
Updated 12-Apr-22 6:13am
v2
Comments
Richard MacCutchan 13-Apr-22 3:42am    
I think you need to Rework a lot of your code. For example:
        if(!commandfile){
          //if (commandfile) {
            if(commandfile.timeout) {

If commandfile is null, then trying to access commandfile.timeout will likely cause the code to fail.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900