'Discord.js v13 | ReactionRole.findOneAndUpdate() does not update data in mongoose
Code:
const role = interaction.options.getRole('role');
const description = interaction.options.getString('description');
const emoji = interaction.options.getString('emoji');
const parsedEmoji = Util.parseEmoji(emoji);
if (role.position >= interaction.guild.me.roles.highest.position) {
const embed = new MessageEmbed()
.setColor('RED')
.setTitle('Error:')
.setDescription(`I can not add roles that are higher than mine`)
.setTimestamp()
.setFooter({ text: `Phantom Bot v${config.version}` });
return interaction.reply({ embeds: [embed], ephemeral: true });
}
ReactionRole.findOne({ guild_id: interaction.guild.id }, (err, settings) => {
if (err) {
const embed = new MessageEmbed()
.setColor('RED')
.setTitle('Error:')
.setDescription(`There was an error while adding the reaction role`)
.setTimestamp()
.setFooter({ text: `Phantom Bot v${config.version}` });
return interaction.reply({ embeds: [embed], ephemeral: true });
}
if (!settings) {
new ReactionRole({
guild_id: interaction.guild.id,
message: 0,
roles: {
[parsedEmoji.name]: [
role.id,
{
description: description,
id: parsedEmoji.id,
raw: emoji
}
]
}
}).save();
} else {
settings.roles[parsedEmoji.name] = [
role.id,
{
description: description,
id: parsedEmoji.id,
raw: emoji
}
]
ReactionRole.findOneAndUpdate({ guild_id: interaction.guild.id }, settings);
}
const embed = new MessageEmbed()
.setColor('PURPLE')
.setTitle('Reaction Added:')
.setDescription(`Role ${role}\nEmoji: ${emoji}`)
.setTimestamp()
.setFooter({ text: `Phantom Bot v${config.version}` });
interaction.reply({ embeds: [embed] });
});
Issue:
For some reason if the settings do exist in the else statement, it doesn't actually update it in the Mongoose database. It actually doesn't touch it at all. I've tried awaiting the ReactionRole.findOneAndUpdate but I got an error saying I couldn't await it.
How can I fix this?
Any help would be appreciated!
Solution 1:[1]
Fixed buy making the function an async, then it would allow await.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | killrebeest |
