Как обновить массив объектов mongodb с помощью discord.js команда

#node.js #arrays #mongodb #discord #discord.js

Вопрос:

привет, у меня есть команда, которая добавляет панель ролей реакции панель выглядит так, и a может добавить более 2, но если я допустил ошибку с панелью, я должен удалить всю панель, чтобы исправить ее и создать новую

for example когда я хочу добавить новую реакцию на панель, я набираю $add @role 😀 , так как я могу выполнить команду, которая начинается с $edit 2 @role 😀 редактирования второго массива

изображение панели discord

когда я допустил ошибку с панелью, поэтому мне нужен способ отредактировать массив, который я выбрал 1, 2 или 3 $edit 3 @role 😀

данные mongodb

the code how i add a new role and emoji to the panel

 const { Client, Message, MessageEmbed, Util } = require('discord.js');
const reactionRoles = require('../../models/reactionRoles')
module.exports = {
  name: 'add',
  timeout: 10000,

  run: async (client, message, args) => {

     function catchErr (err,message) {
  return;
 }

    try { 

if(args.length == 0) return message.lineReply(
        new MessageEmbed()
        .setDescription(`**Please mention a role first** `<@Role>`nn**example** `s!add @Role 👠/`nn**you can add a description to the panel like this** `s!add @Role 👠description``)
      );

let role = args[0]

var regex = /d /g;
role = role.match(regex)

role = message.guild.roles.cache.get(role[0])

if(!role) return message.lineReply(
        new MessageEmbed()
        .setDescription(`**Please mention a role first** `<@Role>`nn**example** `s!add @Role 👠/`nn**you can add a description to the panel like this** `s!add @Role 👠description``)
      );

if(args.length < 2) return message.lineReply("Please specify a emoji")

let emoji = args[1]

        const getEmoji = Util.parseEmoji(emoji);

        if(!getEmoji){
         return message.lineReply("`Please put a emoji after you mentioning the role `s!add @Role ðŸ‘``")
        }

let msg = " "

if(args.length > 2){

   msg = args.slice(2).join(" ");

}

const parsedEmoji = Util.parseEmoji(emoji);

    reactionRoles.findOne({ Guild: message.guild.id}, async (err, data) => {
      if(data) {
        
        data.Roles[parsedEmoji.name] = [
          role,
          {
            id: parsedEmoji.id,
            raw: emoji,
            Text: msg,
          },
         
        ];

        await reactionRoles.findOneAndUpdate({ Guild: message.guild.id}, data);
        
      } else {
        
        new reactionRoles({
          Guild: message.guild.id,
          Channel: message.channel.id,
          Message: 0,
          Roles: {
            [parsedEmoji.name]: [
                 role,
                 {
                   id: parsedEmoji.id,
                   raw: emoji,
                   Text: msg,
                 },                
            ],
          },
        }).save();
      }
      message.lineReply("new role added to the `panel`");

    });
}
   catch (err) {
     catchErr (err);
}
}
};