0

Please help me I want to make an Automute but I have a problem

When a muted user left the server the console gives me this error:

/Users/Fred/Desktop/Papera Bot/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149
          const err = new MongooseError(message);
                      ^

MongooseError: Operation `muted-members.insertOne()` buffering timed out after 10000ms
    at Timeout.<anonymous> (/Users/badreddinelaghlid/Desktop/Papera Bot/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149:23)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

then when the user join the server again the bot don't give the mute role to the user

I try to make this codes with mongoose

the schema code of the model:

const client = require("../index");
const Schema = require("../models/muted");

client.on("guildMemberAdd", async(member) => {
    const data = await Schema.findOne({Guild:member.guild.id});
    if (!data) return;
    const user = data.User.findIndex((prop) => prop === member.id);
    if (user == -1) return;
    let muteRole = message.guild.roles.cache.find(role => role.name === 'muted');

    member.roles.add(muteRole.id);
});

the code of guildMemberAdd:

const client = require("../index");
const Schema = require("../models/muted");

client.on("guildMemberAdd", async(member) => {
    const data = await Schema.findOne({Guild:member.guild.id});
    if (!data) return;
    const user = data.User.findIndex((prop) => prop === member.id);
    if (user == -1) return;
    let muteRole = message.guild.roles.cache.find(role => role.name === 'muted');

    member.roles.add(muteRole.id);
});

if you need any information from my code/bot to help me you can tell me guys

thanks for attention!

ftc404
  • 39
  • 7
  • What's your connection looking like? https://stackoverflow.com/questions/65408618/mongooseerror-operation-users-findone-buffering-timed-out-after-10000ms?rq=1 – DemiPixel Oct 11 '21 at 23:33
  • sorry I don't understand, maybe I need to specify my connection? – ftc404 Oct 11 '21 at 23:55
  • Are you sure the connection is successful? Mongo will let you start making queries to schemas before the connection is made. That's probably what's happening here—where is your `mongoose.connect()` and does `mongoose.connect().then(() => console.log('Connected'))` print "Connected"? – DemiPixel Oct 12 '21 at 00:00
  • ah ok, I didn't write this code of connection, where I must write that? – ftc404 Oct 13 '21 at 20:41
  • You need to connect to the mongodb sometime before you use it--presumably near the start of your server starting up. – DemiPixel Oct 13 '21 at 22:17

1 Answers1

0

I had a similar issue sometime last year when I worked with Mongoose. I ran the .findOne query and I got this error MongooseError: Operation projects.findOne() buffering timed out after 10000ms

I found out I was missing the .exec() function which is supposed to execute the query. Added it and my query was executed.

You can read up on it on the Mongoose docs here: https://mongoosejs.com/docs/api.html#query_Query-exec

Uzoamaka
  • 11
  • 2