所以我试图用 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)});
}
});
}}};
答案 0 :(得分:0)
我发现了我的问题,我没有给键添加值,所以最后我得到了这个:(也添加了其他东西)
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)});
}
});
}}};