1.0.7 • Published 11 months ago

giveaway-cord.js v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

🎉 • 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

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago