我正在使用Discord.js在Discord Bot上创建氏族系统。
我遇到的麻烦是我正在尝试创建一个函数,以检查用户是否已经在氏族中,或者氏族所有者是否在尝试建立另一个氏族(如果他们已经在氏族中)。我目前能够阻止用户创建另一个氏族(如果已经存在相同的名称)
if (clans) return message.channel.send(`**NateBot |** **Error Whilst Creating Clan** ❌\n\n*The Clan with the name **\`${name}\`** already exists!*`);
但是要检查是否有人已经在建立氏族,或者所有者是否正在建立氏族(如果他们已经在氏族中)。
if (!clans) return message.channel.send(`**NateBot |** **You are already in a Clan silly!** ❌\n\n*Possible reasons are because you're either the Owner of this clan or you are a member of the existing clan you joined.*`);
完整代码: createclan.js
const Discord = require('discord.js');
const db = require(`quick.db`)
const moment = require("moment");
exports.run = async (client, message, args, color) => {
let name = args.splice(0).join(" ")
if (!name) return message.channel.send("**NateBot |** You must specify a Clan Name ")
if (message.author.bot) return message.channel.send(`**NateBot |** **Bots cannot use the Clans System!**`)
let clanowner = message.author.username
let clanownerid = message.author.id
let clanowneravatar = message.author.displayAvatarURL
let clanownertag = message.author.tag
//Other
let names = name
let date = moment().format('MMMM Do YYYY, h:mm:ss a')
let clans = await db.fetch(`customclans_${name}`)
if (clans) return message.channel.send(`**NateBot |** **Error Whilst Creating Clan** ❌\n\n*The Clan with the name **\`${name}\`** already exists!*`);
if (!clans) return message.channel.send(`**NateBot |** **You are already in a Clan!** ❌\n\n*Possible reasons are because you're either the Owner of this clan or you are a member of the existing clan you joined.*`);
db.set(`customclans_${name}.name`, names) // Name of Clan
db.set(`customclans_${name}.clanowner`, clanowner) // Owner of Clan
db.set(`customclans_${name}.clanownerid`, clanownerid) // Owner ID of Clan
db.set(`customclans_${name}.clanownertag`, clanownertag) // Owner ID of Clan
db.set(`customclans_${name}.clanowneravatar`, clanowneravatar) // Owner Avatar of Clan user.tag
db.set(`customclans_${name}.date`, date) //Date clan was created
let embed = new Discord.RichEmbed()
.setTitle(`**Custom Clans**`)
.setDescription(`**You created a Clan!** ✅\n\n**Tag Name »** ${name}\n*View your clan with **n!claninfo***`)
.setColor(`#39db69`)
.setFooter(`Note: Clans are Global across servers.`)
message.channel.send(embed)
}
exports.conf = {
aliases: ['setbio'],
cooldown: "10"
}
exports.help = {
name: "setinfo",
description: "Set your info then tell your friends about you",
usage: "setinfo <text>"
}
我已经尝试过这些方法,但无济于事。在这里寻求有关如何解决此问题的帮助。谢谢。
答案 0 :(得分:0)
据我了解,不可能使用类似的数据结构。创建氏族时,请尝试将其ID写入另一个表并进行检查。据quick.db
文档了解,它不允许您进行复杂的数据库选择。如果您打算使用一些复杂的结构,则该数据库将不是最佳选择。最好使用Mysql或MongoDB的mongoose模块来解决问题。使用和调整数据库数据将更加复杂。尽管mongo具有相当友好的界面,但这将使您可以进行一些更复杂的检查。