diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-03-20 01:47:19 -0400 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2025-03-20 01:47:19 -0400 |
| commit | c06c0be2e7520ceaf5284472d0d99c7417aceb7a (patch) | |
| tree | 22cd41cc51c0cdd345bf2133c6ed85772b6d306f /bot/src/commands/timer.js | |
| parent | bdeef58376711e9a49c3b6f26aaf3fc65fa6200b (diff) | |
| download | AleeBot-c06c0be2e7520ceaf5284472d0d99c7417aceb7a.tar.gz AleeBot-c06c0be2e7520ceaf5284472d0d99c7417aceb7a.tar.bz2 AleeBot-c06c0be2e7520ceaf5284472d0d99c7417aceb7a.zip | |
New command; New logging feature; QOTD (WIP)
Diffstat (limited to 'bot/src/commands/timer.js')
| -rw-r--r-- | bot/src/commands/timer.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/bot/src/commands/timer.js b/bot/src/commands/timer.js new file mode 100644 index 0000000..3b3807e --- /dev/null +++ b/bot/src/commands/timer.js @@ -0,0 +1,51 @@ +import { SlashCommandBuilder, time, TimestampStyles } from 'discord.js'; + +export default { + data: new SlashCommandBuilder() + .setName('timer') + .setDescription('Reminds you for something after a certain amount of time.') + .addIntegerOption(option => + option + .setName('seconds') + .setDescription('Seconds to wait for.')) + .addIntegerOption(option => + option + .setName('minutes') + .setDescription('Minutes to wait for.')) + .addIntegerOption(option => + option + .setName('hours') + .setDescription('Hours to wait for.')) + .addStringOption(option => + option + .setName('message') + .setDescription('Enter the message you want to be reminded of.')), + async execute(interaction) { + let timer = 0; + const seconds = interaction.options.getInteger('seconds') || 0; + const minutes = interaction.options.getInteger('minutes') || 0; + const hours = interaction.options.getInteger('hours') || 0; + const message = interaction.options.getString('message'); + const content = message ? `Reason: \`\`\`\n${message}\n\`\`\`` : ''; + if (!seconds && !minutes && !hours) return await interaction.reply({ content: 'Please provide a time to wait for.', ephemeral: true }); + + timer = seconds + (minutes * 60) + (hours * 3600); + + if (timer > 0) { + const date = new Date(); + date.setSeconds(date.getSeconds() + timer); + const timeString = time(date, TimestampStyles.RelativeTime); + await interaction.reply(`Timer set! Will remind you ${timeString}`); + } + + setTimeout(async function(){ + if (interaction.guild) { + let remindChannel = interaction.client.channels.cache.get(interaction.channel.id); + if (!remindChannel) return console.error('Unknown channel.'); + return await remindChannel.send({ content: `${interaction.user}, You have been reminded.${message ? '\n\n' + content : ''}` }); + } else { + return await interaction.user.send({ content: `You have been reminded.${message ? '\n\n' + content : ''}` }); + } + }, timer * 1000); + } +}; |
