Fixed commands

This commit is contained in:
Emotion 2021-10-09 20:31:19 +13:00
parent 75c6d307de
commit ad53371b3d
4 changed files with 39 additions and 27 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules
package-lock.json
giveaways.js
config.json
giveaways.json

View file

@ -6,7 +6,7 @@ module.exports = {
options: [
{
name: 'Winners',
name: 'winners',
description: 'How many winners the giveaway should have',
type: 'INTEGER',
required: true
@ -41,14 +41,14 @@ module.exports = {
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,
@ -61,5 +61,6 @@ module.exports = {
});
interaction.reply(`Giveaway started in ${giveawayChannel}!`);
}
}
};

View file

@ -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
// 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 === messages.guild.id) ||
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 === messages.guild.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
})
});
});
}
};

View file

@ -59,4 +59,4 @@ module.exports = {
});
}
}
};