kandi background
kandi background
Explore Kits
kandi background
Explore Kits
Explore all Discord open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Discord

@discordjs/voice@0.9.0

v1.16.6

GB Studio v3.0.3

BetterDiscord v1.5.2

1.5.5 / 2021-11-10

discord.js

@discordjs/voice@0.9.0

whatsapp-web.js

v1.16.6

gb-studio

GB Studio v3.0.3

BetterDiscord

BetterDiscord v1.5.2

bottender

1.5.5 / 2021-11-10

Popular Libraries in Discord

discord.js

by discordjs javascript

star image 18961 Apache-2.0

A powerful JavaScript library for interacting with the Discord API

discord.py

by Rapptz python

star image 10275 MIT

An API wrapper for Discord written in Python.

Google-Play-Music-Desktop-Player-UNOFFICIAL-

by MarshallOfSound javascript

star image 8451 MIT

A beautiful cross platform Desktop Player for Google Play Music

awesome-ctf

by apsdehal javascript

star image 6128 CC0-1.0

A curated list of CTF frameworks, libraries, resources and softwares

whatsapp-web.js

by pedroslopez javascript

star image 6086 Apache-2.0

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app

gb-studio

by chrismaltby c

star image 5995 MIT

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system

xenia

by xenia-project c++

star image 5520 NOASSERTION

Xbox 360 Emulator Research Project

BetterDiscord

by BetterDiscord javascript

star image 4145 NOASSERTION

Better Discord enhances Discord desktop app with new features.

discord-api-docs

by discord typescript

star image 4043

Official Discord API Documentation

discord.js

by discordjs javascript

star image 18961 Apache-2.0

A powerful JavaScript library for interacting with the Discord API

discord.py

by Rapptz python

star image 10275 MIT

An API wrapper for Discord written in Python.

Google-Play-Music-Desktop-Player-UNOFFICIAL-

by MarshallOfSound javascript

star image 8451 MIT

A beautiful cross platform Desktop Player for Google Play Music

awesome-ctf

by apsdehal javascript

star image 6128 CC0-1.0

A curated list of CTF frameworks, libraries, resources and softwares

whatsapp-web.js

by pedroslopez javascript

star image 6086 Apache-2.0

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app

gb-studio

by chrismaltby c

star image 5995 MIT

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system

xenia

by xenia-project c++

star image 5520 NOASSERTION

Xbox 360 Emulator Research Project

BetterDiscord

by BetterDiscord javascript

star image 4145 NOASSERTION

Better Discord enhances Discord desktop app with new features.

discord-api-docs

by discord typescript

star image 4043

Official Discord API Documentation

Trending New libraries in Discord

fosscord

by fosscord javascript

star image 3576 AGPL-3.0

Fosscord is a free open source selfhostable discord compatible communication platform

Impostor

by Impostor csharp

star image 1963 GPL-3.0

Impostor - An open source reimplementation of the Among Us Server

pycord

by Pycord-Development python

star image 1944 MIT

Pycord, a maintained fork of discord.py, is a python wrapper for the Discord API

epicgames-freebies-claimer

by Revadike javascript

star image 1686 MIT

Claim available free game promotions from the Epic Games Store.

Discord-MusicBot

by SudhanPlayz javascript

star image 1586 NOASSERTION

An advanced discord music bot, supports Spotify, Soundcloud, YouTube with Shuffling, Volume Control and Web Dashboard with Slash Commands support!

git-notify

by jevakallio typescript

star image 1261 MIT

🙉 📣 Communicate important updates to your team via git commit messages

disc-11

by zhycorp typescript

star image 1223 BSD-3-Clause

A dedicated open-source Discord bot for Zhycorp based on our Discord bot template with more features. Easy to use, and with no coding required.

bird-bot

by natewong1313 python

star image 1187 MIT

A Nintendo Switch checkout bot. Currently supports Walmart and Best buy

Aliucord

by Aliucord java

star image 980 OSL-3.0

A modification for the Discord Android App

fosscord

by fosscord javascript

star image 3576 AGPL-3.0

Fosscord is a free open source selfhostable discord compatible communication platform

Impostor

by Impostor csharp

star image 1963 GPL-3.0

Impostor - An open source reimplementation of the Among Us Server

pycord

by Pycord-Development python

star image 1944 MIT

Pycord, a maintained fork of discord.py, is a python wrapper for the Discord API

epicgames-freebies-claimer

by Revadike javascript

star image 1686 MIT

Claim available free game promotions from the Epic Games Store.

Discord-MusicBot

by SudhanPlayz javascript

star image 1586 NOASSERTION

An advanced discord music bot, supports Spotify, Soundcloud, YouTube with Shuffling, Volume Control and Web Dashboard with Slash Commands support!

git-notify

by jevakallio typescript

star image 1261 MIT

🙉 📣 Communicate important updates to your team via git commit messages

disc-11

by zhycorp typescript

star image 1223 BSD-3-Clause

A dedicated open-source Discord bot for Zhycorp based on our Discord bot template with more features. Easy to use, and with no coding required.

bird-bot

by natewong1313 python

star image 1187 MIT

A Nintendo Switch checkout bot. Currently supports Walmart and Best buy

Aliucord

by Aliucord java

star image 980 OSL-3.0

A modification for the Discord Android App

Top Authors in Discord

1

35 Libraries

2619

2

24 Libraries

608

3

15 Libraries

185

4

15 Libraries

140

5

15 Libraries

213

6

13 Libraries

21787

7

13 Libraries

126

8

13 Libraries

191

9

12 Libraries

144

10

12 Libraries

4359

1

35 Libraries

2619

2

24 Libraries

608

3

15 Libraries

185

4

15 Libraries

140

5

15 Libraries

213

6

13 Libraries

21787

7

13 Libraries

126

8

13 Libraries

191

9

12 Libraries

144

10

12 Libraries

4359

Trending Kits in Discord

No Trending Kits are available at this moment for Discord

Trending Discussions on Discord

    discord.js-commando enabling and working with mongodb
    How can you create a pop-up window in Discord that accepts an input from the user?
    Reply to a suggestion with a reaction
    How do I fix CLIENT_MISSING_INTENTS error?
    Is there a way to access the children of a CategoryChannel before it is deleted? [Discord.js]
    How do I get mobile status for discord bot by directly modifying IDENTIFY packet?
    Changing Category/Channels Permissions Returns Error "Missing Permissions" - Novus/Discord.py
    Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
    How to setup .NET 6 with Dapper Identity and Discord Login
    How to check if a bot can DM a user

QUESTION

discord.js-commando enabling and working with mongodb

Asked 2022-Apr-01 at 17:52

I'm trying to create a discord bot, specifically the wedding team.

I am using a MongoDB database. Now everything works and is saved, but there is one problem, the data is saved for the second and third rounds, etc.

That is, the checks that I added do not work. I am trying to find data through const exists = Marry.findOne({ message.author.id });, everything finds, I checked with console log.

But when I try to validate it just doesn't work. if (exists == message.author.id) { return message.channel.send("You are already married!"); }

What could be the problem? Help me please!

Maybe instead userID: message.author.id i just need to find for the value message.author.id. Is it possible?

1const { Command } = require("discord.js-commando");
2const mongoose = require("mongoose");
3
4mongoose.connect('mongodb+srv://admon:admin@cluster0.sobzp.mongodb.net/dbname?retryWrites=true&w=majority');
5
6//create Schema
7
8const marrySchema = new mongoose.Schema({
9    userID: {
10        type: mongoose.SchemaTypes.String,
11        required: true
12    },
13
14    userMarryID: {
15        type: mongoose.SchemaTypes.String,
16        required: true
17    },
18
19    userPartnerID: {
20        type: mongoose.SchemaTypes.String,
21        required: true
22    }
23});
24
25const Marry = mongoose.model('Marry', marrySchema);
26
27module.exports = class MarryCommand extends Command {
28    constructor(client) {
29        super(client, {
30            name: "marry",
31            memberName: "marry",
32            group: "test",
33            description: "Marry the mentioned user",
34            guildOnly: true,
35            args: [{
36                key: "userToMarry",
37                prompt: "Please select the member you wish to marry.",
38                type: "member",
39            }, ],
40        });
41    }
42
43    run(message, { userToMarry }) {
44        const exists = Marry.findOne({ userID: message.author.id });
45        const married = Marry.findOne({ userID: userToMarry.id });
46
47        if (!userToMarry) {
48            return message.channel.send("Please try again with a valid user.");
49        }
50        if (exists == message.author.id) {
51            return message.channel.send("You are already married!");
52        }
53        if (married == userToMarry.id) {
54            return message.channel.send("This user is already married!");
55        }
56        if (userToMarry.id == message.author.id) {
57            return message.channel.send("You cannot marry yourself!");
58        }
59        if (exists != message.author.id && married != userToMarry.id) {
60            message.channel.send(
61                    `**Important announcement!**
62    
63    ${message.author} makes a marriage proposal ${userToMarry}
64    
65    Are you ready to get married?`
66                )
67                .then((message) => {
68                    message.react("👍")
69                    .then(() => message.react("👎"))
70                    .catch(() => {
71                        //code
72                    });
73                    message.awaitReactions((reaction, user) =>
74                        user.id == userToMarry.id && (reaction.emoji.name == "👍" || reaction.emoji.name == "👎"), {
75                            max: 1,
76                            time: 10000,
77                            errors: ["time"]
78                        }
79                    ).then((collected) => {
80                        const reaction = collected.first();
81                        if (reaction.emoji.name === "👎") {
82                            return message.channel.send("I think **no**...");
83                        }
84                        if (reaction.emoji.name === "👍") {
85                                const createdExists = new Marry({
86                                    userID: message.author.id,
87                                    userMarryID: message.author.id,
88                                    userPartnerID: userToMarry.id
89                                });
90                                createdExists.save().catch(e => console.log(e));
91
92                                const createdMarried = new Marry({
93                                    userID: userToMarry.id,
94                                    userMarryID: userToMarry.id,
95                                    userPartnerID: message.author.id
96                                });
97                                createdMarried.save().catch(e => console.log(e));
98
99                            message.channel.send(`${message.author} and ${userToMarry} now married!!`)
100                                .catch(() => {
101                                    message.reply(
102                                        "No reaction after 10 seconds, operation canceled"
103                                    );
104                                });
105                        }
106                    }).catch(() => {});
107                }).catch(() => {});
108        }
109    }
110};
111

ANSWER

Answered 2022-Mar-31 at 16:07

So I think you're having an async issue in your code. The query itself should work just fined. However, I suggest you move exists and married outside of run. Maybe paste them under the MongoDB connection and find a way to pass the message.

copy icondownload icon

1const { Command } = require("discord.js-commando");
2const mongoose = require("mongoose");
3
4mongoose.connect('mongodb+srv://admon:admin@cluster0.sobzp.mongodb.net/dbname?retryWrites=true&w=majority');
5
6//create Schema
7
8const marrySchema = new mongoose.Schema({
9    userID: {
10        type: mongoose.SchemaTypes.String,
11        required: true
12    },
13
14    userMarryID: {
15        type: mongoose.SchemaTypes.String,
16        required: true
17    },
18
19    userPartnerID: {
20        type: mongoose.SchemaTypes.String,
21        required: true
22    }
23});
24
25const Marry = mongoose.model('Marry', marrySchema);
26
27module.exports = class MarryCommand extends Command {
28    constructor(client) {
29        super(client, {
30            name: "marry",
31            memberName: "marry",
32            group: "test",
33            description: "Marry the mentioned user",
34            guildOnly: true,
35            args: [{
36                key: "userToMarry",
37                prompt: "Please select the member you wish to marry.",
38                type: "member",
39            }, ],
40        });
41    }
42
43    run(message, { userToMarry }) {
44        const exists = Marry.findOne({ userID: message.author.id });
45        const married = Marry.findOne({ userID: userToMarry.id });
46
47        if (!userToMarry) {
48            return message.channel.send("Please try again with a valid user.");
49        }
50        if (exists == message.author.id) {
51            return message.channel.send("You are already married!");
52        }
53        if (married == userToMarry.id) {
54            return message.channel.send("This user is already married!");
55        }
56        if (userToMarry.id == message.author.id) {
57            return message.channel.send("You cannot marry yourself!");
58        }
59        if (exists != message.author.id && married != userToMarry.id) {
60            message.channel.send(
61                    `**Important announcement!**
62    
63    ${message.author} makes a marriage proposal ${userToMarry}
64    
65    Are you ready to get married?`
66                )
67                .then((message) => {
68                    message.react("👍")
69                    .then(() => message.react("👎"))
70                    .catch(() => {
71                        //code
72                    });
73                    message.awaitReactions((reaction, user) =>
74                        user.id == userToMarry.id && (reaction.emoji.name == "👍" || reaction.emoji.name == "👎"), {
75                            max: 1,
76                            time: 10000,
77                            errors: ["time"]
78                        }
79                    ).then((collected) => {
80                        const reaction = collected.first();
81                        if (reaction.emoji.name === "👎") {
82                            return message.channel.send("I think **no**...");
83                        }
84                        if (reaction.emoji.name === "👍") {
85                                const createdExists = new Marry({
86                                    userID: message.author.id,
87                                    userMarryID: message.author.id,
88                                    userPartnerID: userToMarry.id
89                                });
90                                createdExists.save().catch(e => console.log(e));
91
92                                const createdMarried = new Marry({
93                                    userID: userToMarry.id,
94                                    userMarryID: userToMarry.id,
95                                    userPartnerID: message.author.id
96                                });
97                                createdMarried.save().catch(e => console.log(e));
98
99                            message.channel.send(`${message.author} and ${userToMarry} now married!!`)
100                                .catch(() => {
101                                    message.reply(
102                                        "No reaction after 10 seconds, operation canceled"
103                                    );
104                                });
105                        }
106                    }).catch(() => {});
107                }).catch(() => {});
108        }
109    }
110};
111const Marry = mongoose.model('Marry', marrySchema);
112const exists = Marry.findOne({ message.author.id });
113const married = Marry.findOne({ userToMarry.id });
114

If that doesn't work, another thing you could try is making the findOne queries async inside the run method, like this:

copy icondownload icon

1const { Command } = require("discord.js-commando");
2const mongoose = require("mongoose");
3
4mongoose.connect('mongodb+srv://admon:admin@cluster0.sobzp.mongodb.net/dbname?retryWrites=true&w=majority');
5
6//create Schema
7
8const marrySchema = new mongoose.Schema({
9    userID: {
10        type: mongoose.SchemaTypes.String,
11        required: true
12    },
13
14    userMarryID: {
15        type: mongoose.SchemaTypes.String,
16        required: true
17    },
18
19    userPartnerID: {
20        type: mongoose.SchemaTypes.String,
21        required: true
22    }
23});
24
25const Marry = mongoose.model('Marry', marrySchema);
26
27module.exports = class MarryCommand extends Command {
28    constructor(client) {
29        super(client, {
30            name: "marry",
31            memberName: "marry",
32            group: "test",
33            description: "Marry the mentioned user",
34            guildOnly: true,
35            args: [{
36                key: "userToMarry",
37                prompt: "Please select the member you wish to marry.",
38                type: "member",
39            }, ],
40        });
41    }
42
43    run(message, { userToMarry }) {
44        const exists = Marry.findOne({ userID: message.author.id });
45        const married = Marry.findOne({ userID: userToMarry.id });
46
47        if (!userToMarry) {
48            return message.channel.send("Please try again with a valid user.");
49        }
50        if (exists == message.author.id) {
51            return message.channel.send("You are already married!");
52        }
53        if (married == userToMarry.id) {
54            return message.channel.send("This user is already married!");
55        }
56        if (userToMarry.id == message.author.id) {
57            return message.channel.send("You cannot marry yourself!");
58        }
59        if (exists != message.author.id && married != userToMarry.id) {
60            message.channel.send(
61                    `**Important announcement!**
62    
63    ${message.author} makes a marriage proposal ${userToMarry}
64    
65    Are you ready to get married?`
66                )
67                .then((message) => {
68                    message.react("👍")
69                    .then(() => message.react("👎"))
70                    .catch(() => {
71                        //code
72                    });
73                    message.awaitReactions((reaction, user) =>
74                        user.id == userToMarry.id && (reaction.emoji.name == "👍" || reaction.emoji.name == "👎"), {
75                            max: 1,
76                            time: 10000,
77                            errors: ["time"]
78                        }
79                    ).then((collected) => {
80                        const reaction = collected.first();
81                        if (reaction.emoji.name === "👎") {
82                            return message.channel.send("I think **no**...");
83                        }
84                        if (reaction.emoji.name === "👍") {
85                                const createdExists = new Marry({
86                                    userID: message.author.id,
87                                    userMarryID: message.author.id,
88                                    userPartnerID: userToMarry.id
89                                });
90                                createdExists.save().catch(e => console.log(e));
91
92                                const createdMarried = new Marry({
93                                    userID: userToMarry.id,
94                                    userMarryID: userToMarry.id,
95                                    userPartnerID: message.author.id
96                                });
97                                createdMarried.save().catch(e => console.log(e));
98
99                            message.channel.send(`${message.author} and ${userToMarry} now married!!`)
100                                .catch(() => {
101                                    message.reply(
102                                        "No reaction after 10 seconds, operation canceled"
103                                    );
104                                });
105                        }
106                    }).catch(() => {});
107                }).catch(() => {});
108        }
109    }
110};
111const Marry = mongoose.model('Marry', marrySchema);
112const exists = Marry.findOne({ message.author.id });
113const married = Marry.findOne({ userToMarry.id });
114const married = await db.collection("yourcollectioname").findOne({ message.author.id });
115const exists = await db.collection("yourcollectioname").findOne({ userToMarry.id });
116

Source https://stackoverflow.com/questions/71619299

Community Discussions contain sources that include Stack Exchange Network

    discord.js-commando enabling and working with mongodb
    How can you create a pop-up window in Discord that accepts an input from the user?
    Reply to a suggestion with a reaction
    How do I fix CLIENT_MISSING_INTENTS error?
    Is there a way to access the children of a CategoryChannel before it is deleted? [Discord.js]
    How do I get mobile status for discord bot by directly modifying IDENTIFY packet?
    Changing Category/Channels Permissions Returns Error "Missing Permissions" - Novus/Discord.py
    Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
    How to setup .NET 6 with Dapper Identity and Discord Login
    How to check if a bot can DM a user

QUESTION

discord.js-commando enabling and working with mongodb

Asked 2022-Apr-01 at 17:52

I'm trying to create a discord bot, specifically the wedding team.

I am using a MongoDB database. Now everything works and is saved, but there is one problem, the data is saved for the second and third rounds, etc.

That is, the checks that I added do not work. I am trying to find data through const exists = Marry.findOne({ message.author.id });, everything finds, I checked with console log.

But when I try to validate it just doesn't work. if (exists == message.author.id) { return message.channel.send("You are already married!"); }

What could be the problem? Help me please!

Maybe instead userID: message.author.id i just need to find for the value message.author.id. Is it possible?

1const { Command } = require("discord.js-commando");
2const mongoose = require("mongoose");
3
4mongoose.connect('mongodb+srv://admon:admin@cluster0.sobzp.mongodb.net/dbname?retryWrites=true&w=majority');
5
6//create Schema
7
8const marrySchema = new mongoose.Schema({
9    userID: {
10        type: mongoose.SchemaTypes.String,
11        required: true
12    },
13
14    userMarryID: {
15        type: mongoose.SchemaTypes.String,
16        required: true
17    },
18
19    userPartnerID: {
20        type: mongoose.SchemaTypes.String,
21        required: true
22    }
23});
24
25const Marry = mongoose.model('Marry', marrySchema);
26
27module.exports = class MarryCommand extends Command {
28    constructor(client) {
29        super(client, {
30            name: "marry",
31            memberName: "marry",
32            group: "test",
33            description: "Marry the mentioned user",
34            guildOnly: true,
35            args: [{
36                key: "userToMarry",
37                prompt: "Please select the member you wish to marry.",
38                type: "member",
39            }, ],
40        });
41    }
42
43    run(message, { userToMarry }) {
44        const exists = Marry.findOne({ userID: message.author.id });
45        const married = Marry.findOne({ userID: userToMarry.id });
46
47        if (!userToMarry) {
48            return message.channel.send("Please try again with a valid user.");
49        }
50        if (exists == message.author.id) {
51            return message.channel.send("You are already married!");
52        }
53        if (married == userToMarry.id) {
54            return message.channel.send("This user is already married!");
55        }
56        if (userToMarry.id == message.author.id) {
57            return message.channel.send("You cannot marry yourself!");
58        }
59        if (exists != message.author.id && married != userToMarry.id) {
60            message.channel.send(
61                    `**Important announcement!**
62    
63    ${message.author} makes a marriage proposal ${userToMarry}
64    
65    Are you ready to get married?`
66                )
67                .then((message) => {
68                    message.react("👍")
69                    .then(() => message.react("👎"))
70                    .catch(() => {
71                        //code
72                    });
73                    message.awaitReactions((reaction, user) =>
74                        user.id == userToMarry.id && (reaction.emoji.name == "👍" || reaction.emoji.name == "👎"), {
75                            max: 1,
76                            time: 10000,
77                            errors: ["time"]
78                        }
79                    ).then((collected) => {
80                        const reaction = collected.first();
81                        if (reaction.emoji.name === "👎") {
82                            return message.channel.send("I think **no**...");
83                        }
84                        if (reaction.emoji.name === "👍") {
85                                const createdExists = new Marry({
86                                    userID: message.author.id,
87                                    userMarryID: message.author.id,
88                                    userPartnerID: userToMarry.id
89                                });
90                                createdExists.save().catch(e => console.log(e));
91
92                                const createdMarried = new Marry({
93                                    userID: userToMarry.id,
94                                    userMarryID: userToMarry.id,
95                                    userPartnerID: message.author.id
96                                });
97                                createdMarried.save().catch(e => console.log(e));
98
99                            message.channel.send(`${message.author} and ${userToMarry} now married!!`)
100                                .catch(() => {
101                                    message.reply(
102                                        "No reaction after 10 seconds, operation canceled"
103                                    );
104                                });
105                        }
106                    }).catch(() => {});
107                }).catch(() => {});
108        }
109    }
110};
111

ANSWER

Answered 2022-Mar-31 at 16:07

So I think you're having an async issue in your code. The query itself should work just fined. However, I suggest you move exists and married outside of run. Maybe paste them under the MongoDB connection and find a way to pass the message.

copy icondownload icon

1const { Command } = require("discord.js-commando");
2const mongoose = require("mongoose");
3
4mongoose.connect('mongodb+srv://admon:admin@cluster0.sobzp.mongodb.net/dbname?retryWrites=true&w=majority');
5
6//create Schema
7
8const marrySchema = new mongoose.Schema({
9    userID: {
10        type: mongoose.SchemaTypes.String,
11        required: true
12    },
13
14    userMarryID: {
15        type: mongoose.SchemaTypes.String,
16        required: true
17    },
18
19    userPartnerID: {
20        type: mongoose.SchemaTypes.String,
21        required: true
22    }
23});
24
25const Marry = mongoose.model('Marry', marrySchema);
26
27module.exports = class MarryCommand extends Command {
28    constructor(client) {
29        super(client, {
30            name: "marry",
31            memberName: "marry",
32            group: "test",
33            description: "Marry the mentioned user",
34            guildOnly: true,
35            args: [{
36                key: "userToMarry",
37                prompt: "Please select the member you wish to marry.",
38                type: "member",
39            }, ],
40        });
41    }
42
43    run(message, { userToMarry }) {
44        const exists = Marry.findOne({ userID: message.author.id });
45        const married = Marry.findOne({ userID: userToMarry.id });
46
47        if (!userToMarry) {
48            return message.channel.send("Please try again with a valid user.");
49        }
50        if (exists == message.author.id) {
51            return message.channel.send("You are already married!");
52        }
53        if (married == userToMarry.id) {
54            return message.channel.send("This user is already married!");
55        }
56        if (userToMarry.id == message.author.id) {
57            return message.channel.send("You cannot marry yourself!");
58        }
59        if (exists != message.author.id && married != userToMarry.id) {
60            message.channel.send(
61                    `**Important announcement!**
62    
63    ${message.author} makes a marriage proposal ${userToMarry}
64    
65    Are you ready to get married?`
66                )
67                .then((message) => {
68                    message.react("👍")
69                    .then(() => message.react("👎"))
70                    .catch(() => {
71                        //code
72                    });
73                    message.awaitReactions((reaction, user) =>
74                        user.id == userToMarry.id && (reaction.emoji.name == "👍" || reaction.emoji.name == "👎"), {
75                            max: 1,
76                            time: 10000,
77                            errors: ["time"]
78                        }
79                    ).then((collected) => {
80                        const reaction = collected.first();
81                        if (reaction.emoji.name === "👎") {
82                            return message.channel.send("I think **no**...");
83                        }
84                        if (reaction.emoji.name === "👍") {
85                                const createdExists = new Marry({
86                                    userID: message.author.id,
87                                    userMarryID: message.author.id,
88                                    userPartnerID: userToMarry.id
89                                });
90                                createdExists.save().catch(e => console.log(e));
91
92                                const createdMarried = new Marry({
93                                    userID: userToMarry.id,
94                                    userMarryID: userToMarry.id,
95                                    userPartnerID: message.author.id
96                                });
97                                createdMarried.save().catch(e => console.log(e));
98
99                            message.channel.send(`${message.author} and ${userToMarry} now married!!`)
100                                .catch(() => {
101                                    message.reply(
102                                        "No reaction after 10 seconds, operation canceled"
103                                    );
104                                });
105                        }
106                    }).catch(() => {});
107                }).catch(() => {});
108        }
109    }
110};
111const Marry = mongoose.model('Marry', marrySchema);
112const exists = Marry.findOne({ message.author.id });
113const married = Marry.findOne({ userToMarry.id });
114

If that doesn't work, another thing you could try is making the findOne queries async inside the run method, like this:

copy icondownload icon

1const { Command } = require("discord.js-commando");
2const mongoose = require("mongoose");
3
4mongoose.connect('mongodb+srv://admon:admin@cluster0.sobzp.mongodb.net/dbname?retryWrites=true&w=majority');
5
6//create Schema
7
8const marrySchema = new mongoose.Schema({
9    userID: {
10        type: mongoose.SchemaTypes.String,
11        required: true
12    },
13
14    userMarryID: {
15        type: mongoose.SchemaTypes.String,
16        required: true
17    },
18
19    userPartnerID: {
20        type: mongoose.SchemaTypes.String,
21        required: true
22    }
23});
24
25const Marry = mongoose.model('Marry', marrySchema);
26
27module.exports = class MarryCommand extends Command {
28    constructor(client) {
29        super(client, {
30            name: "marry",
31            memberName: "marry",
32            group: "test",
33            description: "Marry the mentioned user",
34            guildOnly: true,
35            args: [{
36                key: "userToMarry",
37                prompt: "Please select the member you wish to marry.",
38                type: "member",
39            }, ],
40        });
41    }
42
43    run(message, { userToMarry }) {
44        const exists = Marry.findOne({ userID: message.author.id });
45        const married = Marry.findOne({ userID: userToMarry.id });
46
47        if (!userToMarry) {
48            return message.channel.send("Please try again with a valid user.");
49        }
50        if (exists == message.author.id) {
51            return message.channel.send("You are already married!");
52        }
53        if (married == userToMarry.id) {
54            return message.channel.send("This user is already married!");
55        }
56        if (userToMarry.id == message.author.id) {
57            return message.channel.send("You cannot marry yourself!");
58        }
59        if (exists != message.author.id && married != userToMarry.id) {
60            message.channel.send(
61                    `**Important announcement!**
62    
63    ${message.author} makes a marriage proposal ${userToMarry}
64    
65    Are you ready to get married?`
66                )
67                .then((message) => {
68                    message.react("👍")
69                    .then(() => message.react("👎"))
70                    .catch(() => {
71                        //code
72                    });
73                    message.awaitReactions((reaction, user) =>
74                        user.id == userToMarry.id && (reaction.emoji.name == "👍" || reaction.emoji.name == "👎"), {
75                            max: 1,
76                            time: 10000,
77                            errors: ["time"]
78                        }
79                    ).then((collected) => {
80                        const reaction = collected.first();
81                        if (reaction.emoji.name === "👎") {
82                            return message.channel.send("I think **no**...");
83                        }
84                        if (reaction.emoji.name === "👍") {
85                                const createdExists = new Marry({
86                                    userID: message.author.id,
87                                    userMarryID: message.author.id,
88                                    userPartnerID: userToMarry.id
89                                });
90                                createdExists.save().catch(e => console.log(e));
91
92                                const createdMarried = new Marry({
93                                    userID: userToMarry.id,
94                                    userMarryID: userToMarry.id,
95                                    userPartnerID: message.author.id
96                                });
97                                createdMarried.save().catch(e => console.log(e));
98
99                            message.channel.send(`${message.author} and ${userToMarry} now married!!`)
100                                .catch(() => {
101                                    message.reply(
102                                        "No reaction after 10 seconds, operation canceled"
103                                    );
104                                });
105                        }
106                    }).catch(() => {});
107                }).catch(() => {});
108        }
109    }
110};
111const Marry = mongoose.model('Marry', marrySchema);
112const exists = Marry.findOne({ message.author.id });
113const married = Marry.findOne({ userToMarry.id });
114const married = await db.collection("yourcollectioname").findOne({ message.author.id });
115const exists = await db.collection("yourcollectioname").findOne({ userToMarry.id });
116

Source https://stackoverflow.com/questions/71619299