Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
m7rlin committed Aug 15, 2023
1 parent c5b8796 commit 3b77e7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/commands/utils/ping.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
cooldown: 5,
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
.setDescription('Replies with Pong, bot and API latency!'),

async execute(interaction) {
const timestamp = Date.now()
Expand Down
17 changes: 10 additions & 7 deletions src/events/interaction-create.event.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,32 @@ export default {
const cooldownAmount =
(command.cooldown ?? DEFAULT_COMMAND_COOLDOWN) * 1000

if (timestamps.has(interaction.user.id)) {
const expirationTime =
timestamps.get(interaction.user.id) + cooldownAmount
const userId = interaction.user.id

if (timestamps.has(userId)) {
const expirationTime = timestamps.get(userId) + cooldownAmount

if (now < expirationTime) {
const expiredTimestamp = Math.round(expirationTime / 1000)
return interaction.reply({
content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again <t:${expiredTimestamp}:R>.`,
content: `Komendę ${commandName} możesz ponownie użyć <t:${expiredTimestamp}:R>.`,
ephemeral: true,
})
}
}

timestamps.set(interaction.user.id, now)
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount)
// Set cooldown
timestamps.set(userId, now)
// Delete cooldown
setTimeout(() => timestamps.delete(userId), cooldownAmount)

try {
// Execute command
await command.execute(interaction)
} catch (error) {
consola.error(error)
await interaction.reply({
content: 'There was an error while executing this command!',
content: 'Wystąpił błąd podczas wykonywania tego polecenia!',
ephemeral: true,
})
}
Expand Down

0 comments on commit 3b77e7d

Please sign in to comment.