Advertisement
Guest User

Untitled

a guest
Feb 24th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const { Command } = require('@sapphire/framework');
  3.  
  4. class ReminderCommand extends Command {
  5.     constructor(context, options) {
  6.         super(context, {
  7.             ...options,
  8.             name: 'reminder',
  9.             description: 'Set a reminder',
  10.         });
  11.     }
  12.  
  13.     registerApplicationCommands(registry) {
  14.         registry.registerChatInputCommand((builder) =>
  15.             builder
  16.                 .setName(this.name)
  17.                 .setDescription(this.description)
  18.                 .addRoleOption((option) =>
  19.                     option
  20.                         .setName('role')
  21.                         .setDescription('The role to remind'),
  22.                 )
  23.                 .addStringOption((option) =>
  24.                     option
  25.                         .setName('time')
  26.                         .setDescription('The time for the riminder | Time format: `YYYY-MM-DDTHH:MM:SS`'),
  27.                 )
  28.                 .addStringOption((option) =>
  29.                     option
  30.                         .setName('message')
  31.                         .setDescription('The message for the reminder'),
  32.                 ),
  33.         );
  34.     }
  35.  
  36.     async chatInputRun(interaction) {
  37.         const role = interaction.options.getRole('role', true);
  38.         const time = interaction.options.getString('time', true);
  39.         let message = interaction.options.getString('message', false);
  40.  
  41.         if (message == null) {
  42.             message = 'Reminder!';
  43.         }
  44.  
  45.         const delay = parseTime(time);
  46.         if (delay === null) {
  47.             await interaction.reply('Invalid time format Please use a valid time format like `2023-02-22T13:17:00`');
  48.             return;
  49.         }
  50.  
  51.         interaction.reply('Reminder set!');
  52.  
  53.         setTimeout(() => {
  54.             return interaction.channel.send(`${role} ${message}`);
  55.         }, delay);
  56.     }
  57. }
  58.  
  59. function parseTime(time) {
  60.     const targetDate = Date.parse(time);
  61.  
  62.     console.log(targetDate);
  63.  
  64.     if (isNaN(targetDate)) {
  65.         return null;
  66.     }
  67.  
  68.     const milliseconds = targetDate - Date.now();
  69.  
  70.     return milliseconds;
  71. }
  72.  
  73. module.exports = {
  74.     ReminderCommand,
  75. };
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement