Answer the question
In order to leave comments, you need to log in
How to block the creation of an existing promotional code?
Hello, there was such a problem. I wrote a command to generate a promo code. In fact, everything works in it, except for the prohibition on creating an existing promotional code. In my case, there is already a promo code `#jk`, but anyone can still create it. I tried many methods already, nothing helped. Your last hope so to speak.
const Discord = module.require("discord.js");
const fs = require("fs");
const settings = require('../botconfig.json');
module.exports.run = async (bot,message,args) => {
Promo.findOne({guildID: message.guild.id, ownerpromoID: message.author.id}, (err,dat) => {
if(!dat){
let errorMess = new Discord.RichEmbed()
.setColor('RED')
.setDescription(`**Вы отсутствуете в базе данных. Обратитесь к Разработчику** \`Jason Kings#5476\` **для решения проблемы. Код ошибки:** \`775\``)
return message.channel.send(errorMess)
}
if(err) {
let xembed = new Discord.RichEmbed()
.setColor(`RED`)
.setDescription(`**Не удалось создать промокод. Ошибка:** \`${err}\``)
return message.channel.send(xembed)
}
if(!args[0]) return message.delete() && message.channel.send(`<@${message.author.id}>, \`Введите название вашего будущего промокода! Пример: /createpromocode #jk\``).then(msg => msg.delete(15000));
if (!args[0].startsWith("#")) return message.delete() && message.channel.send(`<@${message.author.id}>, \`Название вашего промокода должно начинаться с "#"! Пример: /createpromocode jk\``).then(msg => msg.delete(15000));
if(`${dat.promocode =args[0]}`) return message.delete() && message.channel.send(`<@${message.author.id}>, \`такой промокод уже есть!\``)
if(dat.promocode !=`${dat.promocode ="-"}`) return message.delete() && message.channel.send(`<@${message.author.id}>, \`Вы уже создали свой промокод!\``).then(msg => msg.delete(15000));
message.channel.send(`<@${message.author.id}>, \`Вы успешно создали свой промокод\` **${args[0]}**`)
dat.promocode =`${args[0]}`
dat.lvlpromo =1
dat.save()
})
}
module.exports.help = {
name: "createpromocode"
}
Answer the question
In order to leave comments, you need to log in
I don’t understand well that it doesn’t work out for you, but you have a line in your code:
if(`${dat.promocode =args[0]}`) return message.delete() && message.channel.send(`<@${message.author.id}>, \`такой промокод уже есть!\``)
if (dat.promocode = args[0]) . . .
message.channel.send
message.reply("текст")
dat.promocode
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question