Closed fedesugo closed 3 years ago
ahm where do you do this.client.on
?
its on node_modules manager.js line 464
https://github.com/Androz2091/discord-giveaways/issues/190 If you are using a extended client, take a look at that issue
so what i need to take out?
const config_gw = require('../src/Resources/Config/bot');
bot.config_gw = config;
const { GiveawaysManager } = require("discord-giveaways");
const db = require("quick.db");
const client = require('../src/Resources/Config/bot');
if (!db.get("giveaways")) db.set("giveaways", []);
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
// This function is called when the manager needs to get all the giveaway stored in the database.
async getAllGiveaways() {
// Get all the giveaway in the database
return db.get("giveaways");
}
// This function is called when a giveaway needs to be saved in the database (when a giveaway is created or when a giveaway is edited).
async saveGiveaway(messageID, giveawayData) {
// Add the new one
db.push("giveaways", giveawayData);
// Don't forget to return something!
return true;
}
async editGiveaway(messageID, giveawayData) {
// Gets all the current giveaways
const giveaways = db.get("giveaways");
// Remove the old giveaway from the current giveaways ID
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageID !== messageID);
// Push the new giveaway to the array
newGiveawaysArray.push(giveawayData);
// Save the updated array
db.set("giveaways", newGiveawaysArray);
// Don't forget to return something!
return true;
}
// This function is called when a giveaway needs to be deleted from the database.
async deleteGiveaway(messageID) {
// Remove the giveaway from the array
const newGiveawaysArray = db.get("giveaways").filter((giveaway) => giveaway.messageID !== messageID);
// Save the updated array
db.set("giveaways", newGiveawaysArray);
// Don't forget to return something!
return true;
}
};
// Create a new instance of your new class
const manager = new GiveawayManagerWithOwnDatabase(client, {
storage: false,
updateCountdownEvery: 5000,
default: {
botsCanWin: false,
exemptPermissions: [],
embedColor: "#FF0000",
reaction: config_gw.reaction
}
});
client.giveawaysManager = manager;
// We now have a client.giveawaysManager property to manage our giveaways!
client.giveawaysManager.on("giveawayReactionAdded", (giveaway, member, reaction) => {
try {
if (member.user.bot) return;
const Discord = require("discord.js")
const db = require('quick.db')
let language = db.fetch(`lang_${member.guild.id}`)
if (language === null) language = config_gw.basiclang
const lang = require(`../src/lang/${language}.js`)
let logs = db.fetch(`logs_${member.guild.id}`)
if (logs === null) return;
const salon = member.guild.channels.cache.get(logs);
const Embed = new Discord.MessageEmbed()
.setAuthor(lang.logs.raddtitle)
.setDescription(lang.logs.raddmsg1 + "** **" + "`" + member.user.tag + "`" + "** **" + lang.logs.raddmsg2 + "** **" + "`" + giveaway.messageID + "`" + "** **" + config.reaction)
.setFooter(config_gw.embeds.footers)
.setColor(config_gw.events.addcolor)
.setTimestamp()
salon.send(Embed)
} catch (e) {
return;
}
});
client.giveawaysManager.on("giveawayReactionRemoved", (giveaway, member, reaction) => {
try {
if (member.user.bot) return;
const Discord = require("discord.js")
const db = require('quick.db')
let language = db.fetch(`lang_${member.guild.id}`)
if (language === null) language = config_gw.basiclang
const lang = require(`../src/lang/${language}`)
let logs = db.fetch(`logs_${member.guild.id}`)
if (logs === null) return;
const salon = member.guild.channels.cache.get(logs);
const Embed = new Discord.MessageEmbed()
.setAuthor(lang.logs.rremtitle)
.setDescription(lang.logs.rremmsg1 + "** **" + "`" + member.user.tag + "`" + "** **" + lang.logs.rremmsg2 + "** **" + "`" + giveaway.messageID + "`" + "** **" + config.reaction)
.setFooter(config_gw.embeds.footers)
.setColor(config_gw.events.remcolor)
.setTimestamp()
salon.send(Embed)
} catch (e) {
return;
}
});
the problem is the giveaway manager needs the client that got created with new someClass()
, you do that somewhere right?
so you can either put the manager creation in the file where you do new Client()
const { client } = require('../src/Resources/Config/bot');
const client = new Client();
const GiveawayManagerWithOwnDatabase = require('SomeFileWhereyouPutTheExtendedClass')
const manager = new GiveawayManagerWithOwnDatabase(client, {
storage: false,
updateCountdownEvery: 5000,
default: {
botsCanWin: false,
exemptPermissions: [],
embedColor: "#FF0000",
reaction: config_gw.reaction
}
});
client.giveawaysManager = manager;
require('fileWithGIveawayEvents')(client)
or you add the manager in your extended client = https://github.com/Androz2091/discord-giveaways/issues/190#issuecomment-764833315
but... the real question is, where is this.client.on?
but... the real question is, where is this.client.on?
it's for the raw
discord event in order to to emit giveaway events
and that does not work because the giveaway manager did not reveive a initialized client = const client = new Class()
the only other way as mentioned if he defined the manager in his extended client and does
const manager = new GiveawayManagerWithOwnDatabase(this, {
now the file with giveaway events is Config/Bot?
?
now the file with giveaway events is Config/Bot?
moment, do you have a extended discord client = custom or do you use the default one?
i hace the disable mentions one
not exactly what i asked but nvm
remove const client = require('../src/Resources/Config/bot');
put require('fileWithTheCodeYouSentAbove')(client)
into the file where you do client.login(token)
put module.exports = client => {}
around the whole https://github.com/Androz2091/discord-giveaways/issues/264#issuecomment-823502916 code
i haved like this
Ahm okay if you want everything in your main file... now just add
const manager = new GiveawayManagerWithOwnDatabase(bot, {
storage: false,
updateCountdownEvery: 5000,
default: {
botsCanWin: false,
exemptPermissions: [],
embedColor: "#FF0000",
reaction: config_gw.reaction
}
});
client.giveawaysManager = manager;
ready
now?
WOW!!! THANKS IT WORKS
Module is not working, tells me this.client.on is not a function.