Androz2091 / discord-giveaways

πŸŽ‰ Complete framework to facilitate the creation of giveaways using discord.js
https://discord-giveaways.js.org
MIT License
333 stars 127 forks source link

error pls help me #351

Closed Aditya-coder379 closed 3 years ago

Aditya-coder379 commented 3 years ago

this is the error

node index.js
(node:192) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:192) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
πŸ‘Œ Event loaded: message
πŸ‘Œ Event loaded: ready
πŸ‘Œ Command loaded: create
πŸ‘Œ Command loaded: delete
πŸ‘Œ Command loaded: edit
πŸ‘Œ Command loaded: end
πŸ‘Œ Command loaded: help
πŸ‘Œ Command loaded: list
πŸ‘Œ Command loaded: reroll
πŸ‘Œ Command loaded: restartbot
πŸ‘Œ Command loaded: start
Connection error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  name: 'MongoNetworkError'
}]
    at Pool.<anonymous> (/home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/topologies/server.js:441:11)
    at Pool.emit (events.js:314:20)
    at /home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/pool.js:564:14
    at /home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/pool.js:999:11
    at /home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/connect.js:32:7
    at callback (/home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/connect.js:283:5)
    at Socket.<anonymous> (/home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/connect.js:313:7)
    at Object.onceWrapper (events.js:421:26)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:192) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  name: 'MongoNetworkError'
}]
    at Pool.<anonymous> (/home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/topologies/server.js:441:11)
    at Pool.emit (events.js:314:20)
    at /home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/pool.js:564:14
    at /home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/pool.js:999:11
    at /home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/connect.js:32:7
    at callback (/home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/connect.js:283:5)
    at Socket.<anonymous> (/home/runner/GiveawayBot-1/node_modules/mongodb/lib/core/connection/connect.js:313:7)
    at Object.onceWrapper (events.js:421:26)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:192) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:192) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Ready as Chatty#4358
(node:192) UnhandledPromiseRejectionWarning: MongooseError: Operation `giveaways.find()` buffering timed out after 10000ms
    at Timeout.<anonymous> (/home/runner/GiveawayBot-1/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:198:23)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(node:192) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)`

this is the code 

`const fs = require('fs');

const Discord = require('discord.js');
const client = new Discord.Client();

const config = require('./config.json');
client.config = config;

// Connect to the database
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/giveaways', { useFindAndModify: false });
const db = mongoose.connection;

// Check the connection
db.on('error', console.error.bind(console, 'Connection error:'));
db.once('open', () => {
    console.log('Connected to MongoDB.');
});

// Create the schema for giveaways
const giveawaySchema = new mongoose.Schema({
    messageID: String,
    channelID: String,
    guildID: String,
    startAt: Number,
    endAt: Number,
    ended: Boolean,
    winnerCount: Number,
    prize: String,
    messages: {
        giveaway: String,
        giveawayEnded: String,
        inviteToParticipate: String,
        timeRemaining: String,
        winMessage: String,
        embedFooter: String,
        noWinner: String,
        winners: String,
        endedAt: String,
        hostedBy: String,
        units: {
            seconds: String,
            minutes: String,
            hours: String,
            days: String,
            pluralS: Boolean,
        },
    },
    hostedBy: String,
    winnerIDs: [String],
    reaction: mongoose.Mixed,
    botsCanWin: Boolean,
    embedColor: mongoose.Mixed,
    embedColorEnd: mongoose.Mixed,
    exemptPermissions: [],
    exemptMembers: String,
    bonusEntries: String,
    extraData: mongoose.Mixed,
    lastChance: {
        enabled: Boolean,
        content: String,
        threshold: Number,
        embedColor: mongoose.Mixed
    }
});

// Create the model
const giveawayModel = mongoose.model('giveaways', giveawaySchema);

const { GiveawaysManager } = require('discord-giveaways');
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
    // This function is called when the manager needs to get all giveaways which are stored in the database.
    async getAllGiveaways() {
        // Get all giveaways from the database. We fetch all documents by passing an empty condition.
        return await giveawayModel.find({});
    }

    // This function is called when a giveaway needs to be saved in the database.
    async saveGiveaway(messageID, giveawayData) {
        // Add the new giveaway to the database
        await giveawayModel.create(giveawayData);
        // Don't forget to return something!
        return true;
    }

    // This function is called when a giveaway needs to be edited in the database.
    async editGiveaway(messageID, giveawayData) {
        // Find by messageID and update it
        await giveawayModel.findOneAndUpdate({ messageID: messageID }, giveawayData).exec();
        // 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) {
        // Find by messageID and delete it
        await giveawayModel.findOneAndDelete({ messageID: messageID }).exec();
        // Don't forget to return something!
        return true;
    }
};

// Init discord giveaways
// Create a new instance of your new class
const emoji = 'πŸŽ‰' 
const manager = new GiveawayManagerWithOwnDatabase(client, {
    updateCountdownEvery: 10000,
    default: {
        botsCanWin: config.botsCanWin,
        embedColor: config.embedColor,
        embedColorEnd: config.embedColorEnd,
        reaction:  emoji,
    }
});
// We now have a client.giveawaysManager property to manage our giveaways!

client.giveawaysManager = manager;

client.giveawaysManager.on("giveawayReactionAdded", (giveaway, member, reaction) => {
    if (member.id !== client.user.id){
        console.log(`${member.user.tag} entered giveaway #${giveaway.messageID} (${reaction.emoji.name})`);
    }
});

client.giveawaysManager.on("giveawayReactionRemoved", (giveaway, member, reaction) => {
    if (member.id !== client.user.id){
        console.log(`${member.user.tag} left giveaway #${giveaway.messageID} (${reaction.emoji.name})`);
    }
});

/* Load all events */
fs.readdir("./events/", (_err, files) => {
    files.forEach((file) => {
        if (!file.endsWith(".js")) return;
        const event = require(`./events/${file}`);
        let eventName = file.split(".")[0];
        console.log(`πŸ‘Œ Event loaded: ${eventName}`);
        client.on(eventName, event.bind(null, client));
        delete require.cache[require.resolve(`./events/${file}`)];
    });
});

client.commands = new Discord.Collection();

/* Load all commands */
fs.readdir("./commands/", (_err, files) => {
    files.forEach((file) => {
        if (!file.endsWith(".js")) return;
        let props = require(`./commands/${file}`);
        let commandName = file.split(".")[0];
        client.commands.set(commandName, props);
        console.log(`πŸ‘Œ Command loaded: ${commandName}`);
    });
});

client.giveawaysManager = manager;

// Login
if (client.config.useENV == true) {
    require('dotenv').config();
    client.login(process.env.TOKEN);
}else{
    client.login(config.token);
}
Nico105 commented 3 years ago

DB connection issues are not our job. Is your server properly running?

Aditya-coder379 commented 3 years ago

which server?

Aditya-coder379 commented 3 years ago

i am using repl.it

Aditya-coder379 commented 3 years ago

DB connection issues are not our job. Is your server properly running?

i am using repl.it

Nico105 commented 3 years ago

i am using repl.it

Bruh then why are you providing the default localhost connection string?

Is this your first time mongoose/mongoDB?

Aditya-coder379 commented 3 years ago

i am using repl.it

Bruh then why are you providing the default localhost connection string?

Is this your first time mongoose/mongoDB?

yes

Aditya-coder379 commented 3 years ago

can u help me?

Aditya-coder379 commented 3 years ago

i was using json but i was hosting at heroku and it corrupted every time when I restarted

Nico105 commented 3 years ago

can u help me?

Have you already created a cluster on mongoDBs website?

Aditya-coder379 commented 3 years ago

can u help me?

Have you already created a cluster on mongoDBs website?

yes

Aditya-coder379 commented 3 years ago

with name cluster0

Aditya-coder379 commented 3 years ago

oh no