# @sapphire/plugin-pattern-commands

> Plugin for @sapphire/framework that adds support for pattern commands.

Latest version **6.0.3** (published 2024-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sapphire/plugin-pattern-commands
pnpm add @sapphire/plugin-pattern-commands
yarn add @sapphire/plugin-pattern-commands
bun add @sapphire/plugin-pattern-commands
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 6.0.3 |
| Published | 2024-11-02 |
| First published | 2021-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=v18 |
| Dependencies | 0 |
| Unpacked size | 107.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | @sapphire |
| Maintainers | favna, vladfrangu, kyranet |
| Keywords | sapphiredev, plugin, bot, typescript, ts, yarn, discord, sapphire, pattern-commands |

## Links

- npm: https://www.npmjs.com/package/@sapphire/plugin-pattern-commands
- Repository: https://github.com/sapphiredev/plugins
- Homepage: https://github.com/sapphiredev/plugins/tree/main/packages/pattern-commands
- Issues: https://github.com/sapphiredev/plugins/issues
- npm.io page: https://npm.io/package/@sapphire/plugin-pattern-commands

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 6.0.3 (latest) — 2024-11-02
- 6.0.4-next.77bb4e0 (next) — 2026-03-08
- 6.0.2-pr-534.00b527b.0 (pr-534) — 2024-01-06
- 6.0.2-pr-531.68fab22.0 (pr-531) — 2023-12-29
- 6.0.0-pr-513.cc0467d.0 (pr-513) — 2023-12-05
- 6.0.0-pr-512.86f3d06.0 (pr-512) — 2023-12-04
- 5.0.3-pr-475.0a017c0.0 (pr-475) — 2023-09-06
- 5.0.2-pr-469.d3a0e5e.0 (pr-469) — 2023-08-23
- 5.0.2-pr-465.0a92431.0 (pr-465) — 2023-08-12
- 5.0.2-pr-437.cfcbc0f.0 (pr-437) — 2023-05-03
- 4.2.0-pr-403.05623a4.0 (pr-403) — 2023-01-06
- 4.0.1-pr-363.e4e2a04.0 (pr-363) — 2022-09-25
- 3.1.2-pr-334.52c8c14.0 (pr-334) — 2022-08-08
- 4.0.0-pr-271.0258c7b7.0 (pr-271) — 2022-08-08
- 2.2.1-pr-285.d64fcad.0 (pr-285) — 2022-05-05
- … 767 more at https://npm.io/package/@sapphire/plugin-pattern-commands/versions

## README

<div align="center">

![Sapphire Logo](https://raw.githubusercontent.com/sapphiredev/assets/main/banners/SapphireCommunity.png)

# @sapphire/plugin-pattern-commands

**Plugin for <a href="https://github.com/sapphiredev/framework">@sapphire/framework</a> so you can have pattern commands.**

[![GitHub](https://img.shields.io/github/license/sapphiredev/plugins)](https://github.com/sapphiredev/plugins/blob/main/LICENSE.md)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/plugin-pattern-commands?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/plugin-pattern-commands)
[![npm](https://img.shields.io/npm/v/@sapphire/plugin-pattern-commands?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/plugin-pattern-commands)

</div>

## Description

With pattern commands you can define rulesets to which the bot may respond.

## Important notes

-   Starting August 31, 2022 this plugin will only work with Message Intent. This is because this plugin relies on scanning messages, which is impossible without the intent.

## Features

-   Fully ready for TypeScript!
-   Includes ESM ready entrypoint
-   Type generics for easy extension in TypeScript
-   Input/Output mapping

## Installation

`@sapphire/plugin-pattern-commands` depends on the following packages. Be sure to install these along with this package!

-   [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
-   [`@sapphire/utilities`](https://www.npmjs.com/package/@sapphire/utilities)
-   [`@sapphire/stopwatch`](https://www.npmjs.com/package/@sapphire/stopwatch)
-   [`discord.js`](https://www.npmjs.com/package/discord.js)

You can use the following command to install this package, or replace `npm install` with your package manager of choice.

```sh
npm install @sapphire/plugin-pattern-commands @sapphire/framework @sapphire/utilities @sapphire/stopwatch discord.js
```

---

## Usage

-   Paste this in your Bot.ts (or where you initiate your client)

```typescript
import '@sapphire/plugin-pattern-commands/register';
```

-   Create a new `pattern-commands` directory under `/src`
-   Make your first pattern command:

```typescript
import type { Message } from 'discord.js';
import { PatternCommand } from '@sapphire/plugin-pattern-commands';
import { ApplyOptions } from '@sapphire/decorators';

@ApplyOptions<PatternCommand.Options>({
	aliases: ['cat', 'postman'],
	chance: 85
})
export class AwooCommand extends PatternCommand {
	public messageRun(message: Message) {
		message.reply('Woof!');
	}
}
```

In this example there's a 85% chance when your bot will bark at someone who says cat or postman.
The matcher is case-insensitive and can match at substrings as well (so in the example above the word catnip also can trigger your bot)
For aliases you can use regexp as well, but you have to encapsulate them as a string. For example:

```typescript
@ApplyOptions<PatternCommand.Options>({
    aliases: ['a{3,}'],
})
```

## Buy us some doughnuts

Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

|   Donate With   |                       Address                       |
| :-------------: | :-------------------------------------------------: |
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|      Ko-fi      |      [Click Here](https://sapphirejs.dev/kofi)      |
|     Patreon     |    [Click Here](https://sapphirejs.dev/patreon)     |
|     PayPal      |     [Click Here](https://sapphirejs.dev/paypal)     |

## Contributors

Please make sure to read the [Contributing Guide][contributing] before making a pull request.

Thank you to all the people who already contributed to Sapphire!

<a href="https://github.com/sapphiredev/plugins/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=sapphiredev/plugins" />
</a>

[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md

---
_Source: https://npm.io/package/@sapphire/plugin-pattern-commands · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
