discord.js - 我们如何从 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]})}}})
解决方案
推荐阅读
- jmeter - 将变量打印到 CONSOLE
- google-cloud-platform - 最小实例 Google Cloud Run
- javascript - 绝对类型( import * as alias 语法不适用于 export = class)
- javascript - 更改数字 ro 字符串并正确舍入 JS
- ios - HealthKit -> 查询附有路线的锻炼
- android - get id of each row in onItemClickListener in Android Studio
- c++ - Storing a C++20 function-like object from a forwarding reference?
- azure - Customize project information / fields on Azure DevOps
- r - Appearance control of KNN clusters in R
- python-3.x - Checking keyboardModifiers() in QComboBox selection