如何添加一种方法来检查某人是否已经在部落中/或者他们是否是 Discord 中的部落所有者 - Discord.JS



我正在使用Discord.js在Discord机器人上制作部落系统。

我遇到的问题是我正在尝试创建一个函数,它可以检查用户是否已经在氏族中,或者氏族所有者是否在他们已经在氏族中时尝试创建另一个氏族。如果已经存在相同的名称,我目前能够阻止用户创建另一个氏族:

if (clans) return message.channel.send(`**NateBot |** **Error Whilst Creating Clan** ❌nn*The Clan with the name **`${name}`** already exists!*`);

但是要检查是否有人已经在氏族中试图建立氏族或所有者,如果他们已经在其中,则正在尝试建立氏族。

if (!clans) return message.channel.send(`**NateBot |** **You are already in a Clan silly!** ❌nn*Possible reasons are because you're either the Owner of this clan or you are a member of the existing clan you joined.*`);

完整代码: 创氏族.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** ❌nn*The Clan with the name **`${name}`** already exists!*`);
if (!clans) return message.channel.send(`**NateBot |** **You are already in a Clan!** ❌nn*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!** ✅nn**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>"
}

我已经尝试了这些方法,但无济于事。在这里寻求有关如何解决此问题的帮助。谢谢。

据我了解,使用类似的数据结构是不可能的。创建部落时,请尝试将其 ID 写入另一个表并检查这一点。据我从quick.db文档中了解到,它不允许您进行复杂的数据库选择。如果您打算使用一些复杂的结构,则此数据库将不是最佳选择。最好使用 Mysql 或 MongoDB 的 mongoose 模块来消除和谐。使用和调整数据库数据将更加复杂。虽然 mongo 有一个相当友好的界面 这将允许您进行一些更复杂的检查。

最新更新