Closed Akurejs closed 4 years ago
@Akurejs bruh you just showed ur pass and I'd edit your message.
Also error is not originated from here I tried quickmongo and it works fine with me
rest assured that access to the database does not exist, it is just an example.
For me it is giving this error when the bot turns on, see a screenshot of my code index
@Akurejs hey, try adding await
before every QuickMongo
methods. QuickMongo is asynchronous
.
Also, db.get("giveaways")
is currently null
. Set it before calling GiveawaysManager
.
Like,
if (await db.get("giveaways") === null) await db.set("giveaways", [])
It is also mentioned in quick.db
example.
passed this error now, arrows point to db
if (await db.get("giveaways") === null) await db.set("giveaways", [])
^^
SyntaxError: Unexpected identifier
at wrapSafe (internal/modules/cjs/loader.js:1070:16)
at Module._compile (internal/modules/cjs/loader.js:1120:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47```
Remove that and use
db.get('giveaways').then(data => {
if(!data) db.set('giveaways', [])
})
Hi! Not entirely sure if I fixed the issue or just got something to work??? It doesnt show logs that anything failed when starting since beforehand I had that same issue. I'll embed an image showing what I added to the module Its self. it should help because it works for me And makes sense only because I believe the existing was looking for ongoing giveaways. I could send more screenshots of it working if needed but also note I went and did the same thing stated to replace the quick.db things with quickmongo in index.
Edit: The message doesnt send twice, I just had been mistaken or had two running instances.
sorry, but all the methods you told me didn’t work, they all give the same problem
passed this error now, arrows point to db
if (await db.get ("giveaways") === null) await db.set ("giveaways", []) ^^ SyntaxError: Unexpected identifier at wrapSafe (internal / modules / cjs / loader.js: 1070: 16) at Module._compile (internal / modules / cjs / loader.js: 1120: 27) at Object.Module._extensions..js (internal / modules / cjs / loader.js: 1176: 10) at Module.load (internal / modules / cjs / loader.js: 1000: 32) at Function.Module._load (internal / modules / cjs / loader.js: 899: 14) at Function.executeUserEntryPoint [as runMain] (internal / modules / run_main.js: 74: 12) at internal / main / run_main_module.js: 18: 47```
Ok, heres a method maybe... I have a test version here of this repo with the changes I've made to manager.js
. Maybe try using it and follow something close to this in index.js (or main file unless you shard it)
If this doesnt work then apologies.
const { Database } = require("quickmongo");
const db = new Database(process.env.MongoDB)
//replace process.env.MongoDB with your variable?
const { GiveawaysManager } = require("discord-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 await db.get("giveaways");
}
// This function is called when a giveaway needs to be saved in the database (when a giveaway is$
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 = await 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 = await db.get("giveaways").filter((giveaway) => giveaway.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, // Important - use false instead of a storage path
updateCountdownEvery: 10000,
default: {
everyoneMention: false,
botsCanWin: false,
exemptPermissions: [],
embedColor: "#FF0000",
reaction: "🎉"
}
});
// We now have a giveawaysManager property to access the manager everywhere!
client.giveawaysManager = manager;
@Akurejs
if (await db.get ("giveaways") === null) await db.set ("giveaways", [])
^^
SyntaxError: Unexpected identifier
ah, here's a simple trick. QuickMongo
has events and ready
is one of them. Put that code inside quickmongo#ready
event:
db.on("ready", async () => {
if (await db.get("giveaways") === null) await db.set("giveaways", []);
});
I've tested the code just now on my bot and it worked perfectly. Here is the extended GiveawaysManager class:
const { GiveawaysManager } = require("discord-giveaways");
const { Database } = require("quickmongo");
const db = new Database("mongodb://localhost/giveaways");
db.once("ready", async () => {
if (await db.get("giveaways") === null) await db.set("giveaways", []);
});
class GiveawayManager extends GiveawaysManager {
async getAllGiveaways() {
return await db.get("giveaways");
}
async saveGiveaway(messageID, giveawayData) {
await db.push("giveaways", giveawayData);
return true;
}
async editGiveaway(messageID, giveawayData) {
const giveaways = await db.get("giveaways");
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageID !== messageID);
newGiveawaysArray.push(giveawayData);
await db.set("giveaways", newGiveawaysArray);
return true;
}
async deleteGiveaway(messageID) {
const data = await db.get("giveaways");
const newGiveawaysArray = data.filter((giveaway) => giveaway.messageID !== messageID);
await db.set("giveaways", newGiveawaysArray);
return true;
}
}
module.exports = GiveawayManager;
Thanks @Snowflake107
Missing the example of the bot with mongodb, I'm trying to use quickmongo to use the mongodb database but I'm finding a problem with the package
in the index I add this in place of the quick.db application
and I get this error at the terminal