Skip to content

CreateRule

Imani brown edited this page Aug 1, 2024 · 1 revision

The createRule function

The createRule store is a helper function that allows you to create Rule rules while giving you types the

While developing this package, I encountered an issue with the RuleStore and its type definitions. When using a RuleStore with multiple event types, the type definitions would often become inconsistent or incomplete. To address this problem, I created the createRule function. This function provides a simple and effective solution by ensuring that type definitions remain accurate and reliable, even when multiple event types are used within a single RuleStore.

createRule(identifier: string, event: keyof EventTypes, handler: Function): Rule

  • Purpose: Creates a transformation rule for replacing placeholders in Discord bot messages.
  • Parameters:
    • identifier: Placeholder identifier (e.g., {username}).
    • event: Discord.js event type (e.g., "messageCreate").
    • handler: Function handling the event to return the replacement value.
  • Returns: A Rule object defining the transformation rule.
Clone this wiki locally