From ad53371b3ddd5db0278dd3bde38f715b2a321f11 Mon Sep 17 00:00:00 2001 From: Emotion Date: Sat, 9 Oct 2021 20:31:19 +1300 Subject: [PATCH] Fixed commands --- .gitignore | 3 ++- commands/drop.js | 15 ++++++++------- commands/end.js | 44 +++++++++++++++++++++++++++----------------- commands/reroll.js | 4 ++-- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index f5d9f0a..61bf8ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules package-lock.json giveaways.js -config.json \ No newline at end of file +config.json +giveaways.json \ No newline at end of file diff --git a/commands/drop.js b/commands/drop.js index 9657ee3..6f90cbc 100644 --- a/commands/drop.js +++ b/commands/drop.js @@ -6,7 +6,7 @@ module.exports = { options: [ { - name: 'Winners', + name: 'winners', description: 'How many winners the giveaway should have', type: 'INTEGER', required: true @@ -34,21 +34,21 @@ module.exports = { ephemeral: true }); } - + const giveawayChannel = interaction.options.getChannel('channel'); const giveawayWinnerCount = interaction.options.getInteger('winners'); const giveawayPrize = interaction.options.getString('prize'); - + if(!giveawayChannel.isText()) { return interaction.reply({ - content: ':x: Selected channel; is not text-based.', + content: ':x: Selected channel is not text-based.', ephemeral: true }); } // Start the giveaway client.giveawaysManager.start(giveawayChannel, { - // The number of winners for this frop + // The number of winners for this drop winnerCount: giveawayWinnerCount, // The prize of the giveaway prize: giveawayPrize, @@ -59,7 +59,8 @@ module.exports = { // Messages messages }); - + interaction.reply(`Giveaway started in ${giveawayChannel}!`); + } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/commands/end.js b/commands/end.js index 8fb0069..b4eb670 100644 --- a/commands/end.js +++ b/commands/end.js @@ -1,39 +1,48 @@ const ms = require('ms'); -const messages = require('../utils/messages'); module.exports = { - description: 'End a Giveaway', + + description: 'End a giveaway', + options: [ { name: 'giveaway', - description: 'The giveaway to end (message ID or Giveaway prize.)', + description: 'The giveaway to end (message ID or giveaway prize)', type: 'STRING', required: true } ], run: async (client, interaction) => { - // If the member does not have enough permissions - if(!interaction.member.permission.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){ + + // If the member doesn't have enough permissions + if(!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){ return interaction.reply({ - content: `:x: You need to have the manage messages permissions ot end giveaways.`, + content: ':x: You need to have the manage messages permissions to end giveaways.', ephemeral: true }); } const query = interaction.options.getString('giveaway'); - // try to find the giveaway with prize then with ID - const giveaway = - // Search with giveaway prize - client.giveawaysManager.giveaways.find((g) => g.prize == query && g.guildId === messages.guild.id) || - // Search with giveaway ID - client.giveawaysManager.giveaways.find((g) => g.messageID === query && g.guildId === messages.guild.id); + // try to found the giveaway with prize then with ID + const giveaway = + // Search with giveaway prize + client.giveawaysManager.giveaways.find((g) => g.prize === query && g.guildId === interaction.guild.id) || + // Search with giveaway ID + client.giveawaysManager.giveaways.find((g) => g.messageId === query && g.guildId === interaction.guild.id); - //if no giveaway was found - if(!giveaway){ + // If no giveaway was found + if (!giveaway) { return interaction.reply({ - content: 'Unable to find a giveaway for `'+ query +'`.', + content: 'Unable to find a giveaway for `'+ query + '`.', + ephemeral: true + }); + } + + if (giveaway.ended) { + return interaction.reply({ + content: 'This giveaway is already ended.', ephemeral: true }); } @@ -43,13 +52,14 @@ module.exports = { // Success message .then(() => { // Success message - interaction.reply('Giveaway Ended!') + interaction.reply('Giveaway ended!'); }) .catch((e) => { interaction.reply({ content: e, ephemeral: true - }) + }); }); + } }; \ No newline at end of file diff --git a/commands/reroll.js b/commands/reroll.js index b69d23d..6bffcfd 100644 --- a/commands/reroll.js +++ b/commands/reroll.js @@ -10,7 +10,7 @@ module.exports = { required: true } ], - + run: async (client, interaction) => { // If the member doesn't have enough permissions @@ -59,4 +59,4 @@ module.exports = { }); } -} \ No newline at end of file +}; \ No newline at end of file