Skip to content

Commit

Permalink
feat: opti execution time (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDams authored Oct 18, 2024
1 parent a45d68a commit 986e19b
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,37 @@ module.exports = {
.then(async () => {
const premiumSubCommand = command.options
.filter(option => option.type === ApplicationCommandOptionType.Subcommand && option.premium && option.name === interaction.options.getSubcommand())
const isPremium = await currentGuildIsPremium(interaction.client, interaction.guildId)

if (premiumSubCommand.length > 0 && !isPremium) {
interaction.followUp({
ephemeral: true,
content: ' ',
...premiumCard(interaction.locale),
}).catch((error) => errorHandler(interaction, error))
} else {
CommandsStats.create(interaction.commandName, 'command', interaction)
command?.execute(interaction)
.then(resp => {
if (Array.isArray(resp)) {
resp
.forEach(r => interaction
.followUp(r)
.catch((error) => errorHandler(interaction, error)))
} else {
interaction
.followUp(resp)
.catch((error) => errorHandler(interaction, error))
}
})
.catch(err => {
console.error(err)
errorInteraction(interaction, err, getTranslation('error.execution.command', interaction.locale))
})
if (premiumSubCommand.length > 0) {
const isPremium = await currentGuildIsPremium(interaction.client, interaction.guildId)
if (!isPremium) {
interaction.followUp({
ephemeral: true,
content: ' ',
...premiumCard(interaction.locale),
}).catch((error) => errorHandler(interaction, error))
return
}
}

CommandsStats.create(interaction.commandName, 'command', interaction)
command?.execute(interaction)
.then(resp => {
if (Array.isArray(resp)) {
resp
.forEach(r => interaction
.followUp(r)
.catch((error) => errorHandler(interaction, error)))
} else {
interaction
.followUp(resp)
.catch((error) => errorHandler(interaction, error))
}
})
.catch(err => {
console.error(err)
errorInteraction(interaction, err, getTranslation('error.execution.command', interaction.locale))
})
})
.catch((error) => errorHandler(interaction, error))
}
Expand Down

0 comments on commit 986e19b

Please sign in to comment.