npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

better-giveaways

v1.0.0-beta.3

Published

A modern, feature-rich Discord giveaway manager with TypeScript support, flexible storage adapters, and comprehensive event system

Readme

better-giveaways

npm version License: GPL v3

A modern, feature-rich Discord giveaway manager with TypeScript support, flexible storage adapters, and comprehensive event system. Built as an improved alternative to existing Discord giveaway packages.

✨ Features

  • 🎯 TypeScript Support - Full type safety and IntelliSense
  • 🔧 Flexible Storage - Multiple storage adapters (JSON, Sequelize, custom)
  • 📡 Event-Driven - Comprehensive event system for custom handling
  • 🌍 Internationalization - Multi-language support (English, Czech)
  • 🛡️ Advanced Requirements - Role, account age, server join date, and custom checks
  • Performance Focused - Efficient memory usage and response times
  • 🔄 Automatic Recovery - Restores giveaways after bot restarts
  • 🎲 Reroll Support - Easy winner rerolling functionality

📦 Installation

# Stable version (latest)
npm install better-giveaways@latest
# Unstable version with beta features (dev)
npm install better-giveaways@dev

🤖 Example bot

Beepo's source code

🚀 Quick Start

import { Client } from "discord.js";
import { GiveawayManager, JSONAdapter } from "better-giveaways";

const client = new Client({
  intents: ["Guilds", "GuildMessages", "GuildMessageReactions"],
});

// Initialize with JSON storage
const adapter = new JSONAdapter("./giveaways.json");
const giveawayManager = new GiveawayManager(client, adapter, {
  reaction: "🎉",
  botsCanWin: false,
  language: "en",
});

// Start a giveaway
await giveawayManager.start({
  channelId: "123456789012345678",
  prize: "Discord Nitro",
  winnerCount: 1,
  duration: 24 * 60 * 60 * 1000, // 24 hours
  requirements: {
    requiredRoles: ["roleIdHere"],
    accountAgeMin: Date.now() - 7 * 24 * 60 * 60 * 1000, // 7 days old account
  },
});

📚 API Reference

GiveawayManager

Constructor

new GiveawayManager(client: Client, adapter: BaseAdapter, options: GiveawayManagerOptions)

Methods

  • start(options: GiveawayOptions): Promise<GiveawayData> - Start a new giveaway
  • end(giveawayId: string): Promise<void> - End a giveaway manually
  • reroll(giveawayId: string): Promise<void> - Reroll giveaway winners
  • getGiveaway(giveawayId: string): Promise<GiveawayData | null> - Get giveaway data
  • getAllGiveaways(): Promise<GiveawayData[]> - Get all giveaways
  • deleteGiveaway(giveawayId: string): Promise<void> - Delete a giveaway

Storage Adapters

JSONAdapter

import { JSONAdapter } from "better-giveaways";
const adapter = new JSONAdapter("./data/giveaways.json");

SequelizeAdapter

import { SequelizeAdapter } from "better-giveaways";
import { Sequelize } from "sequelize";

const sequelize = new Sequelize("database", "username", "password", {
  host: "localhost",
  dialect: "mysql",
});
const adapter = new SequelizeAdapter(sequelize);

Custom Adapter

import { BaseAdapter } from "better-giveaways";

class CustomAdapter extends BaseAdapter {
  async save(data: GiveawayData[]): Promise<void> {
    // Your custom save logic
  }

  async load(): Promise<GiveawayData[]> {
    // Your custom load logic
  }
}

Requirements System

const requirements = {
  requiredRoles: ["Member", "Active"], // Role names or IDs
  accountAgeMin: Date.now() - 30 * 24 * 60 * 60 * 1000, // 30 days
  joinedServerBefore: Date.now() - 7 * 24 * 60 * 60 * 1000, // 7 days
  custom: async (userId: string) => {
    // Your custom logic here
    const user = await client.users.fetch(userId);
    const hasNitro = user.premiumType !== null;

    return {
      passed: hasNitro,
      reason: hasNitro ? "User has Nitro" : "User must have Discord Nitro",
    };
  },
};

Event Handling

// Listen to giveaway events
giveawayManager.events.on("giveawayStarted", (giveaway) => {
  console.log(`Giveaway started: ${giveaway.prize}`);
});

giveawayManager.events.on("giveawayEnded", (giveaway, winners) => {
  console.log(
    `Giveaway ended: ${giveaway.prize}, Winners: ${winners.join(", ")}`
  );
});

giveawayManager.events.on("requirementsFailed", (giveaway, user, reason) => {
  console.log(`User ${user.tag} failed requirements: ${reason}`);
});

🌍 Internationalization

Supported languages:

  • en - English (default)
  • cs - Czech
const giveawayManager = new GiveawayManager(client, adapter, {
  reaction: "🎉",
  botsCanWin: false,
  language: "cs", // Use Czech language
});

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

🔗 Links

📞 Support

If you have any questions or need help, please open an issue on GitHub.