Closed ghost closed 3 years ago
Did you create your giveaway manager properly? Please send the code where you do that.
const mongoose = require("mongoose");
const { Client, Collection, MessageEmbed } = require("discord.js");
const Logger = require("../Modules/Logger");
const Functions = require("../Functions");
const { TOKEN, PREFIX, CONNECTIONLINK, AUTHORID, AUTHORID2 } = process.env;
const blacklist = require("../Schemas/KaralisteSchema");
const { Database } = require("quickmongo");
const db = new Database(CONNECTIONLINK);
const { GiveawaysManager } = require("discord-giveaways");
class GiveawayManagerWithOwnDatabase extends GiveawaysManager {
async getAllGiveaways() {
return await db.get("giveaways");
}
async saveGiveaway(messageID, giveawayData) {
db.push("giveaways", giveawayData);
return true;
}
async editGiveaway(messageID, giveawayData) {
const giveaways = await await db.get("giveaways");
const newGiveawaysArray = giveaways.filter(
giveaway => giveaway.messageID !== messageID
);
newGiveawaysArray.push(giveawayData);
db.set("giveaways", newGiveawaysArray);
return true;
}
async deleteGiveaway(messageID) {
const data = await db.get("giveaways");
const newGiveawaysArray = data.filter(
giveaway => giveaway.messageID !== messageID
);
db.set("giveaways", newGiveawaysArray);
return true;
}
}
const manager = new GiveawayManagerWithOwnDatabase(this, {
storage: false,
updateCountdownEvery: 10000,
default: {
botsCanWin: false,
exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR"],
embedColor: "#FF0000",
reaction: "🎉"
}
});
class MyClient extends Client {
constructor(options = {}) {
super(options);
this.commands = new Collection();
this.cooldowns = new Collection();
this.logger = new Logger();
this.function = new Functions(this);
this.giveawaysManager = manager;
this.prefix = PREFIX;
this.token = TOKEN;
this.once("ready", this.ready);
this.on("message", this.handle);
}
async ready() {
console.log(`- Kullanıcı > ${this.user.tag}`);
console.log(`- Sunucu Sayısı > ${this.guilds.cache.size}`);
console.log(`- Komut Sayısı > ${this.commands.size}`);
console.log(
`- Davet URL'si > ${await this.generateInvite({
permissions: ["ADMINISTRATOR"]
})}`
);
this.logger.log("👌 Bot başarıyla aktif oldu!", "READY");
this.guilds.cache
.get("769609767802896394")
.channels.cache.get("801632690415599637")
.edit({ name: `Komut Sayısı: ${this.commands.size}` });
mongoose.connect(CONNECTIONLINK, {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.connection.on("open", () =>
console.log("✔ Veritabanına bağlanıldı.")
);
}
handle(message) {
if (message.author.bot || !message.content.startsWith(this.prefix)) return;
blacklist.findOne({ id: message.author.id }, async (err, data) => {
if (!data) {
let [command, ...args] = message.content
.slice(this.prefix.length)
.trim()
.split(/ +/g);
let cmd =
this.commands.get(command.toLowerCase()) ||
this.commands.find(
data => data.aliases && data.aliases.includes(command.toLowerCase())
);
if (!cmd) return;
if (cmd.guildOnly && !message.guild) return;
if (cmd.usage && !args.length && cmd.usage.includes("<")) {
let reply = "Lütfen bir argüman belirtin.";
if (cmd.usage)
reply += `\n\`\`\`${this.prefix}${cmd.name} ${cmd.usage}\`\`\``;
return message.channel.send(reply);
}
if (cmd.ownerOnly && message.author.id !== (AUTHORID || AUTHORID2))
return;
if (!this.cooldowns.has(cmd.name))
this.cooldowns.set(cmd.name, new Collection());
let now = Date.now();
let timestamps = this.cooldowns.get(cmd.name);
let cooldownAmount = cmd.cooldown * 1000;
if (timestamps.has(message.author.id)) {
const expirationTime =
timestamps.get(message.author.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return;
}
}
timestamps.set(message.author.id, now);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
try {
cmd.exec(message, args);
} catch (e) {
this.logger.log(
`❌ Komut İşleyici Hatası (${cmd.name}): ${e}`,
"ERROR"
);
message.channel.send(
"❌ Bir hata oluştu, lütfen bu sunucudan Eare (bot geliştiricisi) ile iletişime geçin: https://discord.gg/2h3Vv3rfSJ"
);
}
} else {
return;
}
});
}
async launch() {
Promise.all([this.function.load(), super.login(this.token)]);
}
}
module.exports = MyClient;
In some other file you will do const client = new MyClient
won't you? or something similar
In some other file you will do
const client = new MyClient
won't you? or something similar
Yes
const MyClient = require("./Base/Struct/MyClient");
const client = new MyClient();
const DBL = require("dblapi.js");
const dbl = new DBL(process.env.DBLTOKEN, client);
client.launch();
dbl.on("posted", () => console.log("📩 Sunucu sayısı başarıyla gönderildi."));
dbl.on("error", e => console.log(`✖ Bir hata oluştu. ${e}`));
constructor(options = {}) {
super(options);
this.commands = new Collection();
this.cooldowns = new Collection();
this.logger = new Logger();
this.function = new Functions(this);
this.giveawaysManager = new GiveawayManagerWithOwnDatabase(this, {
storage: false,
updateCountdownEvery: 10000,
default: {
botsCanWin: false,
exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR"],
embedColor: "#FF0000",
reaction: "🎉"
}
});
this.prefix = PREFIX;
this.token = TOKEN;
this.once("ready", this.ready);
this.on("message", this.handle);
}
I'm not sure if it works because I do not know classes too well but try it like this
constructor(options = {}) { super(options); this.commands = new Collection(); this.cooldowns = new Collection(); this.logger = new Logger(); this.function = new Functions(this); this.giveawaysManager = new GiveawayManagerWithOwnDatabase(this, { storage: false, updateCountdownEvery: 10000, default: { botsCanWin: false, exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR"], embedColor: "#FF0000", reaction: "🎉" } }); this.prefix = PREFIX; this.token = TOKEN; this.once("ready", this.ready); this.on("message", this.handle); }
I'm not sure if it works because I do not know classes too well but try it like this
the code you sent solved the error, thank you
I'm getting this error in a way I don't know why, can you help me?