我似乎无法弄清楚 quick.db
Posted
技术标签:
【中文标题】我似乎无法弄清楚 quick.db【英文标题】:I can't seem to figure out quick.db 【发布时间】:2021-06-04 16:04:25 【问题描述】:所以我正在尝试使用 discord.js-commando 和 quick.db 创建一个结婚命令,但它似乎不起作用,我不知道为什么。即使 id 存在于数据库中,如果它不存在,它仍会返回调用的代码。这是我的代码,不胜感激!
const Command = require('discord.js-commando');
const db = require("quick.db");
module.exports = class MarryCommand extends Command
constructor(client)
super(client,
name: 'marry',
memberName: 'marry',
group: 'guild',
description: 'Marry the mentioned user',
guildOnly: true,
args: [
key: 'userToMarry',
prompt: 'Please mention the member that you want to marry.',
type: 'member'
]
);
run(message, userToMarry )
const member = userToMarry;
const exists = db.get(message.author.id);
const married = db.get(userToMarry.id);
if (!member)
return message.channel.send(':x: Please try again with a valid user.')
if (exists == message.author.id || married == message.author.id)
return message.channel.send(':x: You already married!')
if (exists == userToMarry.id || married == userToMarry.id)
return message.channel.send(':x: This user is already married!')
if (exists != message.author.id && exists != userToMarry.id && married != userToMarry.id && married != message.author.id)
message.channel.send(`:heart: $userToMarry, do you want marry $message.author?`);
message.channel.awaitMessages(message => message.author.id == userToMarry.id, max: 1).then(collected =>
if (collected.first().content.toLowerCase() == 'no')
return message.channel.send(':x: Looks like a **no** to me...')
if (collected.first().content.toLowerCase() == 'yes')
db.set(message.author.id, partner: userToMarry.id );
db.set(userToMarry.id, partner: message.author.id );
message.channel.send(`:heart: $message.author and $userToMarry are now married!`)
.catch(err =>
message.channel.send(
`:x: Something went wrong when trying to marry this user.`
);
return console.log(err));
);
;
【问题讨论】:
请edit您的问题标题为描述您遇到的问题或您提出的问题的内容。您的标题应该足够清晰和具有描述性,以便对正在扫描搜索结果列表以寻找解决问题的未来网站用户有意义。您当前的标题对此没有任何价值,也没有提供与您的问题相关的信息。 【参考方案1】:我发现了我的问题,我没有为键添加值,所以最后我得到了这个:(也添加了其他东西)
const Command = require('discord.js-commando');
const db = require("quick.db");
module.exports = class MarryCommand extends Command
constructor(client)
super(client,
name: 'marry',
memberName: 'marry',
group: 'other',
description: 'Marry the mentioned user',
guildOnly: true,
args: [
key: 'userToMarry',
prompt: 'Please mention the member that you want to marry.',
type: 'member'
]
);
run(message, userToMarry )
const exists = db.get(`$message.author.id.user`);
const married = db.get(`$userToMarry.id.user`);
if (!userToMarry)
return message.channel.send(':x: Please try again with a valid user.')
if (exists == message.author.id)
return message.channel.send(':x: You are already married!')
if (married == userToMarry.id)
return message.channel.send(':x: This user is already married!')
if (userToMarry.id == message.author.id)
return message.channel.send(':x: You can\'t marry yourself!');
if (exists != message.author.id && married != userToMarry.id)
message.channel.send(`:heart: $userToMarry, do you want marry $message.author?`);
message.channel.awaitMessages(message => message.author.id == userToMarry.id, max: 1).then(collected =>
if (collected.first().content.toLowerCase() == 'no')
return message.channel.send(':x: Looks like a **no** to me...')
if (collected.first().content.toLowerCase() == 'yes')
db.set(message.author.id, user: message.author.id, partner: userToMarry.id );
db.set(userToMarry.id, user: userToMarry.id, partner: message.author.id );
message.channel.send(`:heart: $message.author and $userToMarry are now married!`)
.catch(err =>
message.channel.send(
`:x: Something went wrong when trying to marry this user. $err`
);
return console.log(err));
);
;
【讨论】:
以上是关于我似乎无法弄清楚 quick.db的主要内容,如果未能解决你的问题,请参考以下文章
quick.db 调平系统 - database.updateValue 不是函数