Я создаю клановые системы на боте Discord, используя Discord. js.
У меня проблемы с тем, что я пытаюсь создать функцию, которая проверяет, находится ли пользователь в клане. или если владелец клана пытается создать другой клан, когда они уже в одном. В настоящее время я могу запретить пользователям создавать другой клан, если такое же имя уже существует:
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>"
}
Я пробовал эти методы, но безрезультатно. Обращаться здесь за помощью, как решить эту проблему. Спасибо.