Code Monkey home page Code Monkey logo

eris-giveaways's Introduction

Eris Giveaways

Discord Server GitHub Version

Eris Giveaways is a powerful NodeJS framework that allows you to easily manage giveaways using the Eris library!

Features

  • ⏱️ Easy to use!
  • πŸ”„ Automatic restart after bot crash!
  • πŸ‡«πŸ‡· Support for translations: adapt the strings for your own language!
  • πŸ“ Support for all databases! (default is json)
  • βš™οΈ Very customizable! (prize, duration, winners, ignored permissions, bonus entries, etc...)
  • πŸš€ Super powerful: start, edit, reroll, end, delete and pause giveaways!
  • πŸ’₯ Events: giveawayEnded, giveawayRerolled, giveawayEdited, giveawayPaused, giveawayUnpaused, giveawayDeleted, giveawayReactionAdded, giveawayReactionRemoved, endedGiveawayReactionAdded
  • πŸ•ΈοΈ Support for shards!
  • and much more!

Installations

npm install eris-giveaways

Examples

Launch of the Framework

Before launching your bot with Eris Giveaways, here are some information you need to look at:

Required Intents:

Below are the required intents for the framework to run.

  • guilds
  • guildMessageReactions

Optional Intents

This is an optional intents for faster and better performance. You can either choose to enable these intents or not.

  • guildMembers
// Require Libraries
const Eris = require("eris");
const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMessageReactions", "guildMembers"] }); // Replace "TOKEN" with your bot's real token
const settings = {
    prefix: "g!"
};

// Requires Manager from eris-giveaways
const { GiveawaysManager } = require("eris-giveaways");
// Create a Giveaways Manager
const manager = new GiveawaysManager(client, {
    storage: "./giveaways.json",
    default: {
        botsCanWin: false,
        embedColor: 0xFF0000,
        embedColorEnd: 0x000000,
        reaction: "πŸŽ‰"
    }
});

// We can now access the Giveaways Manager everywhere!
client.giveawaysManager = manager;

client.on("ready", () => {
    console.log(`${client.user.username} is Ready!`);
});

// Connect the bot to Discord
client.connect();

After that, giveaways that are not yet completed will start to be updated again and new giveaways can be started.

Start a Giveaway

client.on("messageCreate", async (message) => {
    if (message.author.bot) return;

    const ms = require("ms") // npm install ms
    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift();

    if (command === "start-giveaways") {
        client.giveawaysManager.start(message.channel, {
            duration: ms(args[0]),
            prize: args.slice(2).join(" "),
            winnerCount: parseInt(args[1])
        });
    }
});

This allows you to start a new giveaway. Once the start() function is called, the giveaway starts, and you only have to observe the result, the library does the rest!

⚠ ATTENTION!

The command examples below (reroll, edit delete, end) can be executed on any server your bot is a member of if a person has the prize or the messageIDof a giveaway. To prevent abuse we recommend to check if the prize or the messageID that was provided by the command user is for a giveaway on the same server, if it is not, then cancel the command execution.

let giveaway = client.giveawaysManager.giveaways.find((g) => g.guildID === message.channel.guild.id && g.prize === args.join(" ")) || client.giveawaysManager.giveaways.find((g) => g.guildID === message.channel.guild.id && g.messageID ==== args[0]);

if (!giveaway) return message.channel.createMessage(`Unable to find giveaway for \`${args.join(" ")}\``);

Reroll a Giveaway

client.on("messageCreate", async (message) => {
    if (message.author.bot) return;

    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift();

    if (command === "reroll") {
        const messageID = args[0];

        client.giveawaysManager.reroll(messageID).then(() => {
            message.channel.createMessage("Giveaway successfully rerolled!");
        }).catch(() => {
            message.channel.createMessage(`No giveaway found for \`${messageID}\`, please check and retry`); 
        });
    }
});

Edit a Giveaway

client.on("messageCreate", async (message) => {
    if (message.author.bot) return;

    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift();

    if (command === "edit") {
        const messageID = args[0];

        client.giveawaysManager.edit(messageID, {
            addTime: 5000, // Add another 5 seconds to the giveaway length
            newWinnerCount: 3, // Set the new winner count to 3
            newPrize: "New Prize!" // Set the new prize
        }).then(() => {
            message.channel.createMessage(`Giveaway successfully edited!`);
        }).catch(() => {
            message.channel.createMessage(`An error has occured, please check and retry`);
        });
    }
});

Coming Soon Features

Here's the current planned list of upcoming and new features which will be release in Eris Giveaways.

  • Support for buttons

eris-giveaways's People

Contributors

dependabot[bot] avatar reinacchi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

eris-giveaways's Issues

Move Repository

I'm going to archive this repository and will no longer maintain it as eris-giveaways will be moved to GiviesFramework. This new framework will include new and better features such as giveaways, utils, and more!

This repository will be archived before April 2022 or the full release of the new framework. If you have any questions, feel free to drop some comments and I'll reply as best as possible.

options.time is not a positive number

Error: the title
Code:

ctx.giveawaysManager.start(message.channel, {
            time: ms(args[0]),
            winnerCount: parseInt(args[1].replace("w", "")),
            prize: args.slice(2).join(" ")
        }).catch(e=>console.log(e))

When I run #start 10s 1w test

Events not being fired

Hi, I'm using this package for my bot and i notice that no event is being fired,

Screen.Recording.2022-08-09.at.12.23.57.PM.mov

Unknown Emoji Error

the error: (on giveaway start)

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

DiscordRESTError [10014]: Unknown Emoji
    at RequestHandler.request (/home/runner/uriel/node_modules/eris/lib/rest/RequestHandler.js:75:15)
    at Gaby.addMessageReaction (/home/runner/uriel/node_modules/eris/lib/Client.js:308:36)
    at Message.addReaction (/home/runner/uriel/node_modules/eris/lib/structures/Message.js:393:48)
    at /home/runner/uriel/node_modules/eris-giveaways/src/Manager.js:477:27

my code:

const manager = new GiveawaysManager(client, {
    storage: "./giveaways.json",
    default: {
        botsCanWin: false,
        embedColor: 0x0380EC,
        embedColorEnd: 0x0380EC,
        reaction: "πŸŽ‰",
        lastChance: {
          enabled: true,
          content: `O tempo estΓ‘ acabando!`,
          threshold: 11000,
          embedColor: 0x0380EC
        }
    }
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.