所以我试图用 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)});
}
});
}}};