A simple and efficient giveaway management system for Discord bots using discord.js
. This package allows you to create, manage,
pause, resume, and end giveaways with ease.
npm install @zibot/giveaway
-
🎉 Create giveaways with customizable duration and prizes
-
✋ Pause and resume giveaways
-
🏆 Automatically pick winners when the giveaway ends
-
📋 Fetch active giveaways
-
🎭 Role-based participation
-
🟦 Button-based interaction
const { Client, GatewayIntentBits } = require("discord.js");
const { Giveaways } = require("@zibot/giveaway");
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
const giveaways = new Giveaways(client, {
store: "./giveaways.json",
updateInterval: 60000, // 1 minute
});
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag}`);
giveaways.init();
});
client.login("YOUR_BOT_TOKEN");
giveaways.createGiveaway(
"channel", // The channel where the giveaway will be posted
"Free Nitro", // Prize name
60000, // Duration in milliseconds (1 minute)
1, // Number of winners
{ content: "🎉 Giveaway Started! 🎉" }, // Optional custom message
);
const messageId = "123456789012345678"; // ID of message giveaway
giveaways.editGiveaway(messageId, {
prize: "New Awesome Prize", // Prize name
duration: 300000, // Duration in milliseconds (5 minute)
winnerCount: 2 // Number of winners
});
console.log("Giveaway updated!");
const res = giveaways.joinGiveaway("message-id", "user-id", "role");
/* res:
-2: requiredRole
-1: 404 or paused
0: already joined
1: join ok
*/
giveaways.leaveGiveaway("message-id", "user-id");
giveaways.endGiveaway("message-id");
giveaways.pauseGiveaway("message-id");
giveaways.unpauseGiveaway("message-id");
const activeGiveaways = giveaways.fetchGiveaways();
console.log(activeGiveaways);
const { EmbedBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } = require("discord.js");
async function startGiveaway(channel) {
const embed = new EmbedBuilder()
.setTitle("🎉 Giveaway!")
.setDescription("Click the button below to enter!")
.setColor("Gold");
const button = new ButtonBuilder()
.setCustomId("join_giveaway")
.setLabel("Join Giveaway")
.setStyle(ButtonStyle.Primary);
const row = new ActionRowBuilder().addComponents(button);
const message = await channel.send({ embeds: [embed], components: [row] });
giveaways.createGiveaway(channel.id, "Awesome Prize", 60000, 1, message);
}
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;
if (interaction.customId === "join_giveaway") {
const joined = giveaways.joinGiveaway(interaction.message.id, interaction.user.id);
if (joined) {
await interaction.reply({ content: "You have joined the giveaway!", ephemeral: true });
} else {
await interaction.reply({ content: "You are already in the giveaway!", ephemeral: true });
}
}
});
You can listen to various events for better control over the giveaway process:
giveaways.on("giveawayCreated", (client, giveaway) => {
console.log(`Giveaway started: ${giveaway.prize} in ${giveaway.channelId}`);
});
giveaways.on("giveawayEdited", (giveaway) => {
console.log(`Giveaway edited: ${giveaway.prize} in ${giveaway.channelId}`);
});
giveaways.on("giveawayEnded", (giveaway, winners) => {
console.log(`Giveaway ended: ${giveaway.prize} in ${giveaway.channelId} with winners: ${winners.join(", ")}`);
});
giveaways.on("userJoined", (giveaway, userId) => {
console.log(`User ${userId} joined giveaway: ${giveaway.prize}`);
});
giveaways.on("userLeft", (giveaway, userId) => {
console.log(`User ${userId} left giveaway: ${giveaway.prize}`);
});
giveaways.on("giveawayPaused", (giveaway) => {
console.log(`Giveaway paused: ${giveaway.prize} in ${giveaway.channelId}`);
});
giveaways.on("giveawayUnpaused", (giveaway) => {
console.log(`Giveaway resumed: ${giveaway.prize} in ${giveaway.channelId}`);
});
giveaways.on("giveawaysSaved", (allgiveaway) => {
console.log(`${allgiveaway.length} Giveaway Saved`);
});
giveaways.on("debug", (d) => {
console.log(d);
});
example bot: GA bot
MIT License
- Ziji - Creator & Maintainer
For any issues or feature requests, please create an issue on the GitHub repository.