Last active
September 3, 2021 02:36
-
-
Save pedroricardo/8f9aa804af14156a20c90659ec30c8f6 to your computer and use it in GitHub Desktop.
Código do tutorial: https://youtu.be/qaArXO_W8kQ - Banco de dados LowDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const low = require('lowdb') | |
const FileSync = require('lowdb/adapters/FileSync') | |
const adapter = new FileSync('banco.json') | |
const db = low(adapter) | |
//criar | |
db.set('servidor2', []) | |
//postar | |
db.get('servidor1').push({ | |
id: "0000000", | |
nick: "pedro", | |
avatar: "link.com/avatar.png" | |
}) | |
//editar | |
db.get('servidor1').find({id: "1111111"}).assign({nick: "paulo novo"}) | |
//buscar | |
let valor = db.get('servidor1').find({id: "1111111"}).value() | |
console.log(valor) | |
//apagar | |
db.get('servidor1').remove({id: "1111111"}).write() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require("discord.js"); //baixar a lib discord.js | |
const client = new Discord.Client(); | |
const config = require("./config.json"); | |
const low = require('lowdb') //banco de dados | |
const FileSync = require('lowdb/adapters/FileSync') | |
const adapter = new FileSync('banco.json') | |
const db = low(adapter) | |
client.on("ready", () => { | |
console.log('Olá Mundo') | |
}) | |
client.on("guildCreate", () => { | |
db.set(guild.id, []).write() | |
}) | |
client.on("message", async message => { | |
if(message.author.bot) return; | |
if(message.channel.type === "dm") return; | |
if(!message.content.startsWith(config.prefix)) return; | |
const args = message.content.slice(config.prefix.length).trim().split(/ +/g); | |
const comando = args.shift().toLowerCase(); | |
if(comando === "criar") { | |
db.get(message.guild.id) | |
.push({ | |
id: message.author.id, | |
nick: message.author.username, | |
avatar: message.author.displayAvatarURL | |
}).write() | |
message.channel.send('Perfil criado com sucesso!') | |
} | |
if(comando === "editar"){ | |
if(!args[0])return message.channel.send('Você esqeceu do argumento ') | |
let [novonome] = args | |
db.get(message.guild.id) | |
.find({id: message.author.id}).assign({nick: novonome}).write() | |
message.channel.send('Perfil editado com sucesso!') | |
} | |
if(comando === "apagar"){ | |
db.get(message.guild.id).remove({id: message.author.id}).write() | |
} | |
}); | |
client.login(config.token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Primeiramente muito obrigado mais uma vez por me responder. ^^ Então, eu ja testei esse codigo tambem e por algum motivo simplesmente não funciona, não entendo pois o codigo em si faz sentido, porem ele não retorna nada. Estou ate agora tentando resolver isso porem nada ;-;