Need some help with Better-SQLite3

Utilizations

Banned
Feedback score
0
Posts
119
Reactions
11
Resources
0
Hello, I am looking for some support using Better-SQLite3 on Discord.js V14.

Here is the simple explenation.
This is how my table is laid out, within my DB - AM looking to fetch the inventory for a user, by their ID (3428572345742352798) in this case. I would like to to output 1x Nitro + 1x Nitro into a message on discord.
Like this
6lqn5Mf.png

Here is my current code.
const target = interaction.member

const pull = await db.prepare('SELECT * FROM inventory WHERE userID=?').get(target.id)
if(!pull) {
const embed1 = new EmbedBuilder()
.setTitle(Items of ${interaction.member})
.setDescription("All the information related to this user is strictly within the SeaShoreMC Server.")
.addFields(({name: "Item's", value: You have no tiems.}))
.setColor("#009e47")
.setFooter({text: "SeashoreMC | PLAY.IP.HERE | MEMBERCOUNT"})
interaction.reply({embeds: [embed1]})
} else {
const embed = new EmbedBuilder()
.setTitle(Level of ${target.username})
.setDescription("All the information related to this user is strictly within the SeaShoreMC Server.")
.addFields(({name: "Item's", value: ITEMSHERE}))
.setColor("#009e47")
.setFooter({text: "SeashoreMC | PLAY.IP.HERE | MEMBERCOUNT"})
interaction.reply({embeds: [embed]})
}

UserIDInventory
34285723457423527981x Nitro
234578237423842094820
34285723457423527981x Nitro
4353465324574573422x Custom color
 
Type
Requesting
Provided by
Individual
Language
  1. JavaScript
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

ThisLightMan

Node.js/Discord.js Developer for Corebot
Supreme
Feedback score
1
Posts
20
Reactions
29
Resources
2
Hey Utilizations, I’m on my phone so this may not turn out great, but hopefully it’ll help you. You’ll want to use db.prepare("sql statement").all(parameters). For your case, you’d want to do something like this: db.prepare("SELECT * FROM tableName WHERE UserID=?").all(yourUserIdHere). That should return an array of items that the user owns.

Edit: I just saw your code spoiler. Essentially just use the same code you used for the pull variable, but use .all instead of .get. The get function only fetches the first match, whereas the all function returns every match.
 
Last edited:

Utilizations

Banned
Feedback score
0
Posts
119
Reactions
11
Resources
0
Hey Utilizations, I’m on my phone so this may not turn out great, but hopefully it’ll help you. You’ll want to use db.prepare("sql statement").all(parameters). For your case, you’d want to do something like this: db.prepare("SELECT * FROM tableName WHERE UserID=?").all(yourUserIdHere). That should return an array of items that the user owns.

Edit: I just saw your code spoiler. Essentially just use the same code you used for the pull variable, but use .all instead of .get. The get function only fetches the first match, whereas the all function returns every match.
Hello, thanks for the help.

I did the changes you stated - and gave it a try. I am currently getting a response of undefined.

const pull = await db.prepare('SELECT * FROM inventory WHERE userID=?').all(interaction.member.id)
if(!pull) {
const embed1 = new EmbedBuilder()
.setTitle(Items of ${interaction.member})
.setDescription("All the information related to this user is strictly within the SeaShoreMC Server.")
.addFields(({name: "Item's", value: You have no items.}))
.setColor("#009e47")
.setFooter({text: "SeashoreMC | PLAY.IP.HERE | MEMBERCOUNT"})
interaction.reply({embeds: [embed1]})
} else {
const embed = new EmbedBuilder()
.setTitle(Itmes of ${interaction.member})
.setDescription("All the information related to this user is strictly within the SeaShoreMC Server.")
.addFields(({name: "Item's", value: ${pull.items}}))
.setColor("#009e47")
.setFooter({text: "SeashoreMC | PLAY.IP.HERE | dwwdwa"})
interaction.reply({embeds: [embed]})

NmAL2Ei.png

BMURob5.png
 
Banned forever. Reason: Creating Multiple Accounts (Luke_Hams, https://builtbybit.com/members/luke_hams.19809/)
Top