# Discord-Giveaway

- A module allowing the simple creation of a discord giveaway with your client supported by Discord.js^14.0.0
- The easiest to use giveaway module.
    
## News

- The finish and stop functionalities have been added directly to the buttons.
- No need to manage the message, it is sent automatically with the `manager.start()`.
- Data modification features (emoji, color etc) have been added and are supported if you follow the detailed instructions below.

## Installation

[![npm](https://img.shields.io/npm/v/discord-giveaway-easy)](https://npmjs.org/discord-giveaway-easy)

[![NPM](https://nodei.co/npm/discord-giveaway-easy.png)](https://npmjs.org/package/discord-giveaway-easy)

## Create a Giveaway.
```js
const discord_giveaway = require("discord-giveaway");
const Discord = require("discord.js");
const intents = new Discord.IntentsBitField(3276799);
const client = new Discord.Client({intents});

client.on("ready", () => {
    console.log("I'm login !")
});

client.on("interactionCreate", async (interaction) => {

    let guild = interaction.guild
    let channel = interaction.channel

      if (interaction.isChatInputCommand() && interaction.commandName === 'giveaway') {

        const time = interaction.options.getString("time")
        const prize = interaction.options.getString("prize")
        const winnerNumber = interaction.options.getNumber("winner_number")

        let manager = new discord_giveaway.giveawaysManager(client);

        manager.start(message.channel, {
        time: time,
        prize: prize,
        winnerNumber: winnerNumber,
        interaction: message,
        buttonType: Discord.ButtonStyle.Primary,
        })
    
    }
});
```

## Show data of the giveaway (panel)

**The "private" parameter represents the argument that will be responsible for putting the message in ephemaral or not (optional)**

```js
const discord_giveaway = require("discord-giveaway");
const Discord = require("discord.js");
const intents = new Discord.IntentsBitField(3276799);
const client = new Discord.Client({intents});
  

client.giveawayPanelManager = new discord_giveaway.giveawaysPanel(bot) // ⚠️ don't forget so that the system works


client.on("ready", () => {
    console.log("I'm login !")
});

client.on("interactionCreate", async (interaction) => {

     if (interaction.isChatInputCommand() && interaction.commandName === 'gpanel') {
     
      let private = interaction.options.getBoolean("private")

      client.giveawayPanelManager.panel(message, private)
    
    }
});
```

## Set new value to existing parameter (emoji, color)

**The "newEmoji" and "newColor" parameters represent the arguments that will be responsible for replacing the other already existing parameters.**

```js
const discord_giveaway = require("discord-giveaway");
const Discord = require("discord.js");
const intents = new Discord.IntentsBitField(3276799);
const client = new Discord.Client({intents});
  

client.giveawayPanelManager = new discord_giveaway.giveawaysPanel(bot) // ⚠️ don't forget so that the system works


client.on("ready", () => {
    console.log("I'm login !")
});

client.on("messageCreate", async message => {

    if(message.content === "!giveaway setConfig") {

      let newEmoji = "✅"
      let newColor = "#ffffff"

      client.giveawayPanelManager.setConfig(message, {
      emoji: newEmoji,
      color: newColor
    })
    
    }
});

client.on("interactionCreate", async (interaction) => {

     if (interaction.isChatInputCommand() && interaction.commandName === 'gconfig') {
     
      let newEmoji = interaction.options.getString("emoji")
      let newColor = interaction.options.getString("color")
      let newGiveawayEnable = interaction.options.getString("enable")
      let newLanguage = interaction.options.getString("language")

     client.giveawayPanelManager.setConfig(message, {
          emoji: newEmoji,
          color: newColor,
          giveawayEnable: newGiveawayEnable,
          language: newLanguage
        })
    
    }
});
```

## Image

### Start Giveaway
![img](https://camo.githubusercontent.com/188ce8e68cfe5442af0c80420d5f468e13579db28e5b6ead262e8d8871febd60/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3935373336343736303534303737343437342f313033343834333938373533313533343335362f756e6b6e6f776e2e706e67)

### Stop Giveaway
![img](https://camo.githubusercontent.com/7f465de6e8e10a0fd9072f6da8df640c9683e6664b3e189d20fbc8922e15955c/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3935373336343736303534303737343437342f313033343834343135333635313134363839342f756e6b6e6f776e2e706e67)

### Reroll Giveaway and end giveaway
![img](https://camo.githubusercontent.com/0cae5af3f0664144e63470608a8f535a0748e477454838002a88df1576960d46/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3935373336343736303534303737343437342f313033343834343035393431373731383834342f756e6b6e6f776e2e706e67)
![img](https://camo.githubusercontent.com/5847bbdb34df4dee7bbaf1496de15afc4b56ca3be617270c1f01baeee1bf4b46/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3935373336343736303534303737343437342f313033343834343038333634343031303532362f756e6b6e6f776e2e706e67)

#
#
#
## Concrete example

The system below is compatible with the [discord.js guide](https://discordjs.guide/#before-you-begin)!

- [creating slash commands](https://discordjs.guide/creating-your-bot/slash-commands.html)
- [advanced creation](https://discordjs.guide/slash-commands/advanced-creation.html)

### giveaway commands
```js
const Discord = require('discord.js')
const discord_giveaway = require("discord-giveaway-easy")

module.exports = {

  data: new Discord.SlashCommandBuilder()
    .setName("giveaway")
    .setDescription("The manager of the giveaway")
    .setDMPermission(false)
    .setDefaultMemberPermissions(Discord.PermissionFlagsBits.ManageMessages)
    .addSubcommand(subcommand => 
      subcommand
      .setName('start')
			.setDescription('Start a giveaway')
			.addStringOption(option => 
        option.setName("titre")
        .setDescription("Title of giveaway")
        .setRequired(true)
        .setAutocomplete(false)
        )
      .addStringOption(option => 
        option.setName("time")
        .setDescription("Time of giveaway")
        .setRequired(true)
        .setAutocomplete(false)
        )
      .addNumberOption(option => 
        option.setName("winner_number")
        .setDescription("The number of the giveaway winner")
        .setRequired(true)
        .setAutocomplete(false)
        ),
      )
      .addSubcommand( subCommand =>
        subCommand
        .setName('set')
        .setDescription('Edit the current data.')
        .addStringOption(option => 
          option.setName("emoji")
          .setDescription("The new Emoji")
          .setRequired(false)
          .setAutocomplete(false)
          )
        .addStringOption(option => 
          option.setName("color")
          .setDescription("The new color")
          .setRequired(false)
          .setAutocomplete(false)
          )
        .addBooleanOption(option => 
          option.setName("enable")
          .setDescription("Disable giveaway system")
          .setRequired(false)
          )
        .addStringOption(option => 
          option.setName("language")
           .setDescription("New language")
           .setRequired(false)
           .setAutocomplete(false)
          ),
      )
      .addSubcommand( subCommand =>
        subCommand
        .setName('info')
        .setDescription('Give current data of the module')
        .addBooleanOption(option => 
          option.setName("priver")
          .setDescription("Choice to send privately or to everyone")
          .setRequired(false)
          ),
      ),
      
    

  async run(bot, message, args) {

    
      if (args.getSubcommand() === "start") {

        let title = args.getString("titre")
        let time = args.getString("time")
        let winnerNumber = args.getNumber("winner_number")
    
        let manager = new discord_giveaway.giveawaysManager(bot)
        
    
        manager.start(message.channel, {
          time: time,
          prize: title,
          winnerNumber: winnerNumber,
          buttonType: Discord.ButtonStyle.Primary,
          interaction: message
        })
      }



      if (args.getSubcommand() === "set") {

        let newEmoji = args.getString("emoji")
        let newColor = args.getString("color")
        let newGiveawayEnable = args.getBoolean("enable")
        let newLanguage = args.getString("language")
        
        bot.giveawayPanelManager.setConfig(message, {
          emoji: newEmoji,
          color: newColor,
          giveawayEnable: newGiveawayEnable,
          language: newLanguage
        })
      }



      if (args.getSubcommand() === "info") {

        let private = args.getBoolean("priver")
        bot.giveawayPanelManager.panel(message, private)
      }
    
    

  
  }


}
```

# Other

To contact the owner of this module, you can join his [discord server](discord.gg/DXbpKPk6FX) and ask him a question.\
For anything else, ditto, join his [discord server](discord.gg/DXbpKPk6FX).

*(careful, this discord server is on french!)*