giveaway-cord.js

1.0.7 • Public • Published

🎉 • giveaway-cord.js Introduction

📕 • Requirements:

Discord.js - v13+

📑 • Install:

npm install giveaway-cord.js

📑 • Functions:

.startGiveaway - Hosts the giveaway

.enterGiveaway - let the user join the giveaway

.leaveGiveaway - remove the user from the giveaway

📜 • Example:

const { Client, Message, MessageActionRow, MessageButton, MessageEmbed } = require('discord.js');
const GiveawayManager = require('giveaway-cord.js');

const giveawayManager = new GiveawayManager();

module.exports = {
  name: 'start',
  premium: false,
  disable: false,
  timeout: 25,

  run: async (client, message, args) => {
    const giveawayChannel = message.channel;

    const giveawayPrize = args[0] || 'Awesome Prize';
    const giveawayDuration = parseInt(args[1]) || 60;
    const giveaway = giveawayManager.startGiveaway(giveawayChannel, giveawayDuration, giveawayPrize);

    const embed = new MessageEmbed()
      .setColor('#0099ff')
      .setTitle('Giveaway Time!')
      .setDescription(`React with 🎉 to enter the giveaway!\nPrize: ${giveawayPrize}\nDuration: ${giveawayDuration} seconds`)
      .setTimestamp();

    const joinButton = new MessageButton()
      .setCustomId('join_giveaway')
      .setLabel('Join Giveaway')
      .setStyle('SUCCESS');

    const actionRow = new MessageActionRow().addComponents(joinButton);

    const giveawayMessage = await message.channel.send({ embeds: [embed], components: [actionRow] });

    const collector = giveawayMessage.createMessageComponentCollector({ componentType: 'BUTTON', time: giveawayDuration * 1000 });

    collector.on('collect', async (interaction) => {
      if (interaction.customId === 'join_giveaway' && !interaction.user.bot) {
        if (giveaway.participants.has(interaction.user.username)) {

          const leaveButton = new MessageButton()
            .setCustomId('leave_giveaway')
            .setLabel('Leave Giveaway')
            .setStyle('DANGER');

          const newActionRow = new MessageActionRow().addComponents(leaveButton);

          await interaction.reply({ content: 'You have already joined the giveaway!', components: [newActionRow], ephemeral: true });
        } else {
          giveawayManager.enterGiveaway(giveaway, interaction.user.username);
          await interaction.reply({ content: 'You have joined the giveaway!', ephemeral: true });
        }
      } 
    });
  }
}

🔗 • Links:

Support - https://discord.gg/WFWnMAP5Uk

Package Sidebar

Install

npm i giveaway-cord.js

Weekly Downloads

31

Version

1.0.7

License

ISC

Unpacked Size

4.24 kB

Total Files

3

Last publish

Collaborators

  • xlelords