Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. const discord = require ( "discord.js" ) ;
  2.  
  3. module. exports . run = async ( bot , message , args ) => {
  4.  
  5. // Arguments that we need later.
  6. var item = "" ;
  7. var time ;
  8. var winnerCount ;
  9.  
  10. // Check if you have perms to do this command.
  11. if ( ! message. member . hasPermission ( "MANAGE_MESSAGES" ) ) return message. channel . send ( "Sorry you can't do this" ) ;
  12.  
  13. //! giveaway numberWinners second itemTo Win.
  14.  
  15. // Request the number of winners.
  16. winnerCount = args [ 0 ] ;
  17. // Time how long it must last.
  18. time = args [ 1 ] ;
  19. // What prize you can win.
  20. item = args. splice ( 2 , args. length ) . join ( "" ) ;
  21.  
  22. // Delete the message that has just been created by the user.
  23. message. delete ( ) ;
  24.  
  25. // Calculate expiration date.
  26. var date = new Date ( ) . getTime ( ) ;
  27. var dateTime = new Date ( date + ( time * 1000 ) ) ;
  28.  
  29. // Create embed.
  30. var giveawayEmbed = new discord. RichEmbed ( )
  31. . setTitle ( "🎉 ** GIVEAWAY ** 🎉" )
  32. . setFooter ( ` Expires : $ { dateTime } ` )
  33. . setDescription ( item ) ;
  34.  
  35. // Send embed and put the response on the popper.
  36. var embedSend = await message. channel . send ( giveawayEmbed ) ;
  37. embedSend. react ( "🎉" ) ;
  38.  
  39. // Set a timeout that goes off after the number of seconds.
  40. setTimeout ( function ( ) {
  41.  
  42. // Arguments that we need.
  43. var random = 0 ;
  44. var winners = [ ] ;
  45. var inList = false ;
  46.  
  47. // Get the users who have responded to the giveaway.
  48. var peopleReacted = embedSend. reactions . get ( "🎉" ) . users . array ( ) ;
  49.  
  50. // Here we are going to go over all the people and see if the bone is in between
  51. // We must remove the bot from the list and then we continue.
  52. for ( var i = 0 ; i <people Reacted. length ; i ++ ) {
  53. if ( peopleReacted [ i ] . id == bot. user . id ) {
  54. people Reacted. splice ( i , 1 ) ;
  55. continuous ;
  56. }
  57. }
  58.  
  59. // Here we check if someone has participated.
  60. if ( peopleReacted. length == 0 ) {
  61. return message. channel . send ( "No one has won so the bot wins." ) ;
  62. }
  63.  
  64. // We will temporarily check if too many people have participated in the competition.
  65. if ( peopleReacted. length < winnerCount ) {
  66. return message. channel . send ( "There are too few people who participated, that's why the bot won." ) ;
  67. }
  68.  
  69. // We will create a random number for the number of winners that we have previously entered and place the user in an array.
  70. for ( var i = 0 ; i < winnerCount ; i ++ ) {
  71.  
  72. inList = false ;
  73.  
  74. // Creating a random number so that we can choose a user.
  75. random = Math . floor ( Math . random ( ) * people Reacted. length ) ;
  76.  
  77. // If a winner is already in the winners list then we have to search for another winner again.
  78. for ( var y = 0 ; y < winners. length ; y ++ ) {
  79. // Check if the selected winner is already in the list.
  80. if ( winners [ y ] == peopleReacted [ random ] ) {
  81. // We put i 1 less so that we can continue in the list.
  82. i -;
  83. // We set this to true so that we know it is already in the list.
  84. inList = true ;
  85. break ;
  86. }
  87. }
  88.  
  89. // If this is not in the list, we will add it.
  90. if ( ! inList ) {
  91. winners. push ( peopleReacted [ random ] ) ;
  92. }
  93.  
  94. }
  95.  
  96. // We will send a message for every winner.
  97. for ( var i = 0 ; i < winners. length ; i ++ ) {
  98. message. channel . send ( "Congratulations" + winners [ i ] + ` ! You have won ** $ { item } ** .` ) ;
  99. }
  100.  
  101. } , 1000 * time ) ;
  102.  
  103.  
  104. }
  105.  
  106. module. exports . help = {
  107. name : "giveaway" ,
  108. description : "Start a giveaway"
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement