0

why wont it recognize this code? its confusing me it should recognize it or has something changed in node/discord that I am not aware of? if i use my command -balance -clear 10 ect it gives diffrent undefined parts like

-balance - ypeError: Cannot read properties of undefined (reading 'send') under the return message.channel.send command

-clear 10 is message.reply is not a function

This is the error im getting

MongoParseError: option usefindandmodify is not supported
    at parseOptions (Roleplay\node_modules\mongodb\lib\connection_string.js:280:15)
    at new MongoClient (\Roleplay\node_modules\mongodb\lib\mongo_client.js:62:63)
    at \Roleplay\node_modules\mongoose\lib\connection.js:784:16
    at new Promise (<anonymous>)
    at NativeConnection.Connection.openUri (\Roleplay\node_modules\mongoose\lib\connection.js:781:19)
    at \Roleplay\node_modules\mongoose\lib\index.js:343:10
    at \Roleplay\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5
    at new Promise (<anonymous>)
    at promiseOrCallback (\Roleplay\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10)
    at Mongoose._promiseOrCallback (\Roleplay\node_modules\mongoose\lib\index.js:1181:10) {
  [Symbol(errorLabels)]: Set(0) {}
}
Bot Is Online
MongooseError: Operation `profilemodels.findOne()` buffering timed out after 10000ms
    at Timeout.<anonymous> (\Roleplay\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:151:23)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)
\Roleplay\commands\beg.js:11
        userID: message.author.id,
                               ^

TypeError: Cannot read properties of undefined (reading 'id')
    at Object.execute (\Roleplay\commands\beg.js:11:32)
    at module.exports (\Roleplay\events\guild\messageCreate.js:58:17)
PS \Roleplay>

this is the code

const profileModel = require("../models/profileSchema");
module.exports = {
  name: "beg",
  aliases: [],
  permissions: [],
  description: "beg for gold",
  async execute(message, args, cmd, client, discord, profileData) {
    const randomNumber = Math.floor(Math.random() * 500) + 1;
    const response = await profileModel.findOneAndUpdate(
      {
        userID: message.author.id,
      },
      {
        $inc: {
          gold: randomNumber,
        },
      }
    );
    return message.channel.send(`${message.author.username}, you begged and received ${randomNumber} **gold**`);
  },
};

This is the messageCreate.js


require ('dotenv').config();

const cooldowns = new Map();
const profileModel = require("../../models/profileSchema");
 module.exports = async (Discord, client, message) => {
    const prefix = process.env.PREFIX;
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    let profileData;
    try {
      profileData = await profileModel.findOne({ userID: message.author.id });
      if (!profileData) {
        let profile = await profileModel.create({
          userID: message.author.id,
          serverID: message.guild.id,
          gold: 1000,
          bank: 0,
        });
        profile.save();
      }
    } catch (err) {
      console.log(err);
    }

    
    if(!message.content.startsWith(prefix) || message.author.bot) return;
    const args = message.content.slice(prefix.length).split(/ +/);
    const cmd = args.shift().toLowerCase();
    const command = client.commands.get(cmd) || client.commands.find(a => a.aliasses && a.aliasses.include(cmd));
  
    
    
    

    if(!cooldowns.has(command.name)){
        cooldowns.set(command.name, new Discord.Collection());
    }

    const current_time = Date.now();
    const time_stamps = cooldowns.get(command.name);
    const cooldown_amount = (command.cooldown) * 1000;

    if(time_stamps.has(message.author.id)){
        const expiration_time = time_stamps.get(message.author.id) + cooldown_amount;

        if(current_time < expiration_time){
            const time_left = (expiration_time - current_time) / 1000;

            return message.reply(`Please wait ${time_left.toFixed(1)} more seconds before using ${command.name}`);
        }
    }
    time_stamps.set(message.author.id, current_time);
    setTimeout(() => time_stamps.delete(message.author.id), cooldown_amount);



    try{
        command.execute(client, args, cmd, message, Discord, profileData);
}catch (err){
    console.log(err);
}
 };



KazTeko
  • 21
  • 6
  • Can we see how you call the command and what all arguments you pass it? It seems like the `message` variable might be something else which might cause these errors – Caladan Jun 02 '22 at 14:34
  • Like Caladan said, check the file `events\guild\messageCreate.js`, line 58 and check that you are passing the correct arguments. They may not both be in the same order. Correct either the command file or event file. – Crispy Jun 02 '22 at 16:28
  • I have added the messageCreate.js on the end of my post – KazTeko Jun 03 '22 at 16:13

1 Answers1

0

Explanations for different errors:

  • Cannot read properties of undefined (reading 'id'): The reason for this error is just the order in which you give the arguments for your command. In your messageCreate.js file, you are passing the client as the first argument while in your command, you are expecting the message to be the first one. You have switched the places for the client and message parameter.
  • Operation profilemodels.findOne() buffering timed out after 10000ms: This error happens because you tried to access data from the database before the connection was even established. For more info, you can go here => MongooseError - Operation users.findOne() buffering timed out after 10000ms
  • option usefindandmodify is not supported error, you are passing in the useFindAndModify: The reason for this error is the fact that you are passing in the useFindAndModify option when you are connection to MongoDB but these options are not supported which causes the error. You can look into this SO question for more info => MongoParseError: options useCreateIndex, useFindAndModify are not supported
Caladan
  • 2,261
  • 2
  • 6
  • 19