Skip to content

Commit

Permalink
Aktualisiere Timer-Befehl, um Start- und Stoppaktionen zu unterstützen
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper-Claus committed Apr 16, 2024
1 parent 5643fc3 commit da55d82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
40 changes: 27 additions & 13 deletions commands/utilities/timer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
const { SlashCommandBuilder } = require('discord.js');
const { data } = require('./ping');
// commands/utilities/timer.js
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
module.exports = {
data: new SlashCommandBuilder()
.setName('timer')
.setDescription('Start a timer for a specified amount of time.')
.addIntegerOption(option => option.setName('duration').setDescription('The duration of the timer in seconds.').setRequired(true)),
.setDescription('Startet oder stoppt den Timer')
.addStringOption(option =>
option.setName('action')
.setDescription('Die Aktion ausführen')
.setRequired(true)),
async execute(interaction) {
const { duration } = interaction.options.getInteger('duration');
await interaction.reply(`Timer started for ${duration} seconds.`);
setTimeout(() => {
interaction.followUp('Timer done!');
}, duration * 1000);
}
}

const action = interaction.options.getString('action');

if (action === 'start') {
global.startTime = Date.now();
await interaction.reply('Timer gestartet');
} else if (action === 'stop') {
if (!global.startTime) {
await interaction.reply('Der Timer wurde noch nicht gestartet');
return;
}

const elapsedTime = Date.now() - global.startTime;
const seconds = Math.floor(elapsedTime / 1000);
delete global.startTime;

await interaction.reply(`Timer gestoppt. Vergangene Zeit: ${seconds} Sekunden`);
}
},
};
1 change: 1 addition & 0 deletions deploy-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ const rest = new REST().setToken(token);
}
})();


5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,3 @@ client.on(Events.InteractionCreate, async interaction => {








0 comments on commit da55d82

Please sign in to comment.