'I want my bot to run on several servers with database

so this code below works fine but the problem is I can't run it in all servers that have my bot I used quick.db but It seem to work only in one severs since it takes the last variable. so is there any way to change from quick.db to mongoDB so it work for all servers.

I hope I explain the issue successfully.

Code: so basically what I am trying to do in this code is the bot will send the random messages to a specific text channel from json file specified by user which works fine, but I think I have a problem with the database.

discord.js v12

hosting the bot throw Heroku


index.js file

        require('events').EventEmitter.prototype._maxListeners = 30;
        const Discord = require('discord.js')
        const client = new Discord.Client()
        const ytdl = require('ytdl-core');
        const config = require('./config.json')
        const mongo = require('./mongo')
        const command = require('./command')
        const loadCommands = require('./commands/load-commands')
        const commandBase = require('./commands/command-base')
        const { permission, permissionError } = require('./commands/command-base')
        const cron = require('node-cron')
        const zkrList = require('./zkr.json')
        const logo =
          'URL HERE'
        const db = require(`quick.db`)
        const prefix = "!"
        
        
        let cid;
client.on('ready', async () => {
  await mongo().then((mongoose) => {
    try {
      console.log('Connected to mongo!')
    } finally {
      mongoose.connection.close()
    }
  })
  console.log(`${client.user.tag} is online`);
  console.log(`${client.guilds.cache.size} Servers`);
  console.log(`Server Names:\n[ ${client.guilds.cache.map(g => g.name).join(", \n ")} ]`);


  loadCommands(client)
  cid = client.guilds.cache.map(guild => { db.get(`${guild.id}_channel_`) });


  cron.schedule('*/10 * * * * *', () => {
    const zkrRandom = zkrList[Math.floor(Math.random() * zkrList.length)]
    const zkrEmbed = new Discord.MessageEmbed()


      .setDescription(zkrRandom)
      .setAuthor('XX', logo)
      .setColor('#447a88')




    client.channels.cache.get(cid).send(zkrEmbed);
  })

  client.on("message", async message => {

    if (message.author.bot) {
      return
    }


    console.log(client.guilds.cache.map(guild => { db.get(`${guild.id}_channel_`) }))
    if (!message.member.hasPermission('ADMINISTRATOR') && message.content.startsWith('XX')) return message.reply('YOU DONT HAVE A PERMISSION TO RUN THIS COMMAND.')
    if (!message.content.startsWith(prefix)) return;


    const args = message.content.slice(prefix.length).trim().split(/ +/g)
    const cmd = args[0]
    if (cmd === "s") {
      let c_id = args[1]
      if (!c_id) return message.reply("YOU NEED TO MENTION A TEXT CHANNEL/ID")
      c_id = c_id.replace(/[<#>]/g, '')
      const channelObject = message.guild.channels.cache.get(c_id);

      try { if (channelObject.type === 'voice') return message.reply('YOU CANNOT SEND MESSAGES TO VOICE CHANNEL') } catch (err) { return message.reply('AN ERROR OCCURRED') }



      if (client.channels.cache.get(c_id)) {



        client.guilds.cache.map(guild => { db.set(`${guild.id}_channel_`, c_id) })

        message.reply(`SENDING TO THIS CHANNEL ${message.guild.channels.cache.get(c_id)}`);
        cid = db.get(client.guilds.cache.map(guild => { db.get(`${guild.id}_channel_`) }))



        const zkrRandom = zkrList[Math.floor(Math.random() * zkrList.length)]
        const zkrEmbed = new Discord.MessageEmbed()


          .setDescription(zkrRandom)
          .setAuthor('XX', logo)
          .setColor('#447a88')




        client.channels.cache.get(cid).send(zkrEmbed);



      } else {
        return message.reply("NOT A VALID CHANNEL")
      }


    }
  })

})


client.login(config.token)

zkr.json file

[
    "MESSAGE 1",
    "MESSAGE 2",
    "MESSAGE 3"
]


Solution 1:[1]

You can use any database with guild variables in several servers. Like;

db.set("_channel_", sth)

to

db.set(`${guild.id}_channel_`, sth)

like this. I couldn't understand your question but this is probably what you are thinking.

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 Dharman