首页 > 解决方案 > 我们如何从 quick.db 中获取一个元素而不返回“未定义”?

问题描述

我想通过制作一个不和谐的机器人来给自己一个挑战,但它似乎不起作用。当我执行 -inv 命令时,它返回未定义。有人可以帮忙吗?

let image = cardImages[Math.floor(Math.random() * cardImages.length)];
let dropEmbed = new Discord.MessageEmbed()
  .setTitle('You dropped a card!')
  .setColor('#B2B2FF')
  .setAuthor(`${message.author.username}`)
  .setTimestamp()
  .setImage(image);
  if(image === "https://i.imgur.com/o3McR3i.png"){
    db.push(`cards_${message.author.id}`, {code: 'LICH1' , group: 'randomGroup' , idol: 'RandomIdol' , concept: 'Uncertain'})}
  else if(image === "https://i.imgur.com/XtNE6ca.png"){
    db.push(`cards_${message.author.id}` , {code: 'ELCO1' , group: 'RandomGroup' , idol: 'RandomIdol' , concept: 'Uncertain'})}
  else if(image === "https://i.imgur.com/Kunx7CC.png"){
    db.push(`cards_${message.author.id}` , {code: 'UNSO1', group: 'Uncertain' , idol: 'RandomIdol' , concept: 'Uncertain'})}
{message.channel.send({embeds: [dropEmbed]})}}})


//Inventories
client.on("messageCreate" , message => {if(message.content === "-inv"){
  let inventoryEmbed = new MessageEmbed()
  .setColor('#B2B2FF')
  .setAuthor(`${message.author.username}`)
  .setDescription(`${db.fetch(`cards_${message.author.id}.code`)}`)
  .addFields(
  {name: `${db.fetch(`cards_${message.author.id}.code`)}` , value: `**${db.fetch(`cards_${message.author.id}.group`)}**`})
  .setTimestamp()
  .setFooter('Inventory in development');
  {message.channel.send({embeds : [inventoryEmbed]})}}})

标签: discord.jsquick.db

解决方案


推荐阅读