【问题标题】:How to list stored data using quick db?如何使用快速数据库列出存储的数据?
【发布时间】:2021-09-15 02:29:40
【问题描述】:

我尝试使用 list 命令列出此代码的存储数据,我尝试了很多但它对我不起作用,

client.on("message", message=>{
    if(!message.guild)return;
    if(message.content.startsWith(prefix + "add")){
    let user = message.mentions.users.first()
        
        if(!user) return message.channel.send('**:x: You have to mention someone first.**')
            if(db.fetch(`owner_${user.id}`)) return message.channel.send("**This user is already exists**")
        
        db.set(`owner_${user.id}`, true)
        message.channel.send(new Discord.MessageEmbed().setColor('#4C6E70').setDescription(`**${user} Done.**`)).then(async msg => {
            msg.react("✅")
        })
    }
 }
    });

【问题讨论】:

    标签: discord discord.js quick.db


    【解决方案1】:

    您现在显示的命令是将所有者添加到您的机器人的命令,与列出它们无关,如果您想显示 quick.db 数据库中的所有数据,只需使用 @987654321 @

    如果你想要更高效的东西,我建议你开始使用数组来存储机器人的所有者,使用 db.push() 它看起来像这样:

    client.on("message", message=>{
        if(!message.guild)return;
        if(message.content.startsWith(prefix + "add")){
        let user = message.mentions.users.first()
            
            if(!user) return message.channel.send('**:x: You have to mention someone first.**')
                let owners = db.get('owners') || [] // If there's no owners it will always return an empty array
                if(owners.includes(user.id)) return message.channel.send("**This user is already exists**")
            
            db.push(`owners`,user.id)
            message.channel.send(new Discord.MessageEmbed().setColor('#4C6E70').setDescription(`**${user} Done.**`)).then(async msg => {
                msg.react("✅")
            })
        }
     }
        });
    

    使用数组集,列出可以使用db.get() 的所有者!

        // ...
        if(message.content.startsWith(prefix + "owners")){
          let owners = db.get('owners')
          if(!owners) return message.channel.send('There are no owners!')
          else  message.channel.send('The owners are ' + owners.join(' and '))
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-15
      • 2011-06-12
      • 2016-02-13
      • 1970-01-01
      • 2020-08-22
      • 2013-01-17
      • 1970-01-01
      • 2021-07-19
      相关资源
      最近更新 更多