blob: c86fd209581d9863504794bdf0d002ba6ea766db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { MessageFlags, 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.', flags: MessageFlags.Ephemeral });
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;
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);
}
};
|