Results

Namespace

Type

Tasks allow you to register your own event handlers to be triggered at specific intervals or times.

Tasks may not be registered at runtime (within event handler scopes). They must be registered at the root of your script. You must provide a unique task name for each task you register.

Task event handlers are subject to the same limits of standard event handlers.

See pylon.tasks.cron.

Index

Functions

Functions

cron

  • cron(name: string, cron: string, handler: function): void
  • Registers a task to be ran at fixed times (UTC) or intervals. Each execution of the task is an independent event execution context with it's own limits and context.

    Cron strings are a list of time selectors separated by space. The format can be seen below:

    ┌───── Second (0-59)
    │ ┌───── Minute (0-59 or *)
    │ │ ┌───── Hour (0-23 or *)
    │ │ │ ┌───── Day of Month (1-31 or *)
    │ │ │ │ ┌───── Month (1-12, Jan-Dec, or *)
    │ │ │ │ │ ┌───── Day of Week (1-7, Mon-Sun, or *)
    │ │ │ │ │ │ ┌───── Year (optional, default: *)
    │ │ │ │ │ │ │
    * * * * * * *

    Time fields may specify ranges, lists or intervals w/ offsets.

    Ranges: Every hour from 11AM through 4PM (UTC) on Monday thru Friday: 0 0 11-16 * * Mon-Fri *

    Lists: Every Monday, Wednesday, and Friday at 12PM (UTC): 0 0 12 * * Mon,Wed,Fri *

    Intervals: Every 5th minute, starting from minute 0: 0 0/5 * * * * *

    Note: The current minimum interval Pylon crons can run at are once every 5 minutes. You may schedule up to 5 cron handlers.

    Example A cron that updates a voice channel's name every 10 minutes with the server's member count.

    // Set a constant voice channel id to use for this task.
    const VOICE_CHANNEL_ID = '524396721154176388430416';
    
    // Register a cron task
    pylon.tasks.cron('update_member_count', '0 0/10 * * * * *', async () => {
      const channel = await discord.getGuildVoiceChannel(VOICE_CHANNEL_ID);
      if (!channel) {
        return;
      }
    
      const guild = await discord.getGuild(channel.guildId);
      if (!guild) {
        return;
      }
    
      // Update the voice channel's name with the server's member count.
      await channel.edit({
        name: `${guild.memberCount.toLocaleString()} Members`
      });
    });

    Parameters

    • name: string

      A unique identifier for this task. Must be alphanumeric including -, _, and ..

    • cron: string

      A valid cron string for this task. See the docs for more info.

    • handler: function

      The event handler to call when the cron event fires.

        • () => unknown | Promise<unknown>
        • Returns unknown | Promise<unknown>

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc