【发布时间】: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您的问题标题为描述您遇到的问题或您提出的问题的内容。您的标题应该足够清晰和具有描述性,以便对正在扫描搜索结果列表以寻找解决问题的未来网站用户有意义。您当前的标题对此没有任何价值,也没有提供与您的问题相关的信息。
标签: discord.js quick.db