# disploy

Latest version **0.5.0** (published 2023-02-02) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install disploy
pnpm add disploy
yarn add disploy
bun add disploy
```

Provides the commands `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19`, `20`.

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2023-02-02 |
| First published | 2022-10-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 18 |
| Unpacked size | 377.5 KB |
| Known vulnerabilities | 0 (+3 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 30 |
| Maintainers | tristancamejo |
| Keywords | api, bot, discord, node, typescript, cf-worker |

## Links

- npm: https://www.npmjs.com/package/disploy
- Repository: https://github.com/Disploy/disploy
- Homepage: https://disploy.dev
- npm.io page: https://npm.io/package/disploy

## Dependencies (18)

- [ora](https://npm.io/package/ora.md) ^6.1.2
- [zod](https://npm.io/package/zod.md) ^3.20.2
- [glob](https://npm.io/package/glob.md) ^8.0.3
- [ngrok](https://npm.io/package/ngrok.md) ^4.3.3
- [yargs](https://npm.io/package/yargs.md) ^17.6.2
- [dotenv](https://npm.io/package/dotenv.md) ^16.0.3
- [rollup](https://npm.io/package/rollup.md) ^3.8.1
- [esbuild](https://npm.io/package/esbuild.md) ^0.16.10
- [express](https://npm.io/package/express.md) ^4.18.2
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [inquirer](https://npm.io/package/inquirer.md) ^9.1.4
- [colorette](https://npm.io/package/colorette.md) ^2.0.19
- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3
- [@disploy/rest](https://npm.io/package/@disploy/rest.md) ^1.0.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.0
- [discord-api-types](https://npm.io/package/discord-api-types.md) ^0.37.24
- [import-meta-resolve](https://npm.io/package/import-meta-resolve.md) ^2.2.0
- [rollup-plugin-esbuild](https://npm.io/package/rollup-plugin-esbuild.md) ^5.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2023-02-02
- 0.3.1-dev.1704413961-78c9477.0 (dev) — 2024-01-05
- 0.3.1-dev.1704370051-78c9477.0 — 2024-01-04
- 0.3.1-dev.1704327573-78c9477.0 — 2024-01-04
- 0.3.1-dev.1704283652-78c9477.0 — 2024-01-03
- 0.3.1-dev.1704241150-78c9477.0 — 2024-01-03
- 0.3.1-dev.1704197241-78c9477.0 — 2024-01-02
- 0.3.1-dev.1704154750-78c9477.0 — 2024-01-02
- 0.3.1-dev.1704110848-78c9477.0 — 2024-01-01
- 0.3.1-dev.1704068513-78c9477.0 — 2024-01-01
- 0.3.1-dev.1704024411-78c9477.0 — 2023-12-31
- 0.3.1-dev.1703982087-78c9477.0 — 2023-12-31
- 0.3.1-dev.1703937997-78c9477.0 — 2023-12-30
- 0.3.1-dev.1703895494-78c9477.0 — 2023-12-30
- 0.3.1-dev.1703851601-78c9477.0 — 2023-12-29
- … 855 more at https://npm.io/package/disploy/versions

## README

<div align="center">
	<br />
	<p>
		<a href="https://disploy.dev"><img src="https://disploy.dev/img/logo.svg" alt="disploy" width="200" /></a>
	</p>
    <p>
		<a href="https://vercel.com/?utm_source=disploy&utm_campaign=oss"><img src="https://www.datocms-assets.com/31049/1618983297-powered-by-vercel.svg" alt="Vercel" /></a>
	</p>
    <h3>
        Visit <a href="https://disploy.dev">disploy.dev</a> to get started!
    </h3>
	<br />
	<p>
		<a href="https://discord.gg/E3z8MDnTWn"><img src="https://img.shields.io/discord/901426442242498650?color=5865F2&logo=discord&logoColor=white" alt="Disploy's Discord server" /></a>
		<a href="https://github.com/disploy/Disploy/actions"><img src="https://github.com/Disploy/disploy/actions/workflows/benchmark.yml/badge.svg" alt="Tests status" /></a>
	</p>

</div>

> **Warning**: We're still in development, and packages are published to npm every 12 hours to the `@dev` tag. You can view our [v1.0.0 milestone](https://github.com/Disploy/disploy/milestone/1) to see what features are planned for the first release and their current status.

Disploy is a flexible router for building HTTP interaction-based Discord bots with ease. It's designed to make it easy to build, test and deploy Discord bots.

# Features

Disploy features a [library](#library) and an opinionated [framework](#framework) with tooling inspired by [Next.js](https://nextjs.org).

## Library

> Disploy does not come included with a "server", that's up to you to implement. We have a [guide](https://disploy.dev/docs/Reference/framework-less/) showcasing you how to do so with Express (Node.js) and Deno's inbuilt server.

This is a slimmed-down guide to using Disploy with Next.js as your server.

### Usage with Next.js

The API entry point:

```ts
// Entrypoint - pages/api/interactions.ts
import { createNextAdapter } from 'disploy';
import { ExampleApp } from '../../lib/main';

export default createNextAdapter(ExampleApp);
```

> **Note**: An "adapter" is a function that transforms requests from your server implementation of choice and creates a [`TRequest`](https://disploy.dev/docs/Documentation/disploy/interfaces/TRequest) that's fed into `App#router#entry` which returns a [`Promise<TResponse>`](https://disploy.dev/docs/Documentation/disploy/classes/TResponse) which your adapter should transform and return to Discord.

Setting up the Disploy App:

```ts
// Main Bot - lib/core/main.ts
import { App } from 'disploy';
import commands from './commands/commands';

const clientId = process.env.DISCORD_CLIENT_ID;
const token = process.env.DISCORD_TOKEN;
const publicKey = process.env.DISCORD_PUBLIC_KEY;

if (!clientId || !token || !publicKey) {
	throw new Error('Missing environment variables');
}

export const ExampleApp = new App({
	logger: {
		debug: true,
	},
});

ExampleApp.start({
	clientId,
	token,
	publicKey,
});

for (const command of commands) {
	ExampleApp.commands.registerCommand(command);
}
```

Setting up an array of commands:

```ts
// Command Array - lib/core/commands/commands.ts
import Ping from './core/ping';

const c = [Ping];

export default c;
```

Example command:

```ts
import type { ChatInputInteraction, Command } from 'disploy';

const Ping: Command = {
	name: 'ping',
	description: 'pong!',

	run(interaction: ChatInputInteraction) {
		interaction.reply({
			content: 'Hello World!',
		});
	},
};

export default Ping;
```

## Framework

Disploy comes inbuilt with a CLI that can bundle your bot based on a file system structure, which is inspired by Next.js.

Use the "TypeScript Framework" boilerplate from [`create-disploy-app`](https://github.com/Disploy/create-disploy-app).

```bash
npx create-disploy-app@latest
```

Here are two examples, a command and a message component handler. Keep in mind none of this is exclusive to the framework, the only "framework exclusive" feature showcased here is the file structure and default exports.

```ts
// Example command - commands/ping.ts
import type { Command } from 'disploy';

export default {
	// Command "data"
	name: 'ping',
	description: 'pong!',

	// Command entrypoint
	async run(interaction) {
		if (!interaction.guild) {
			return void interaction.reply({
				content: 'You must use this in a guild.',
			});
		}

		interaction.deferReply(); // Synchronously reply to the incoming HTTP request
		const guild = await interaction.guild.fetch(); // BaseInteraction#guild is a ToBeFetched class, awaiting fetch on it will return the full structure

		// All our methods take in raw JSON (or our Message structure, coming soon)
		return void interaction.editReply({
			content: 'hello world!!!!!!!!',
			components: [
				{
					type: 1,
					components: [
						{
							type: 2,
							label: 'Click me!',
							style: 1,
							custom_id: `ping-${interaction.user.id}`, // You can handle message components with express-like routes.
						},
					],
				},
			],
		});
	},
} satisfies Command;
```

```ts
// Example message component handler - handlers/ping.ts
import type { ButtonHandler } from 'disploy';

export default {
	customId: 'ping-:userId',

	async run(interaction) {
		const originalUser = await interaction.params.getUserParam('userId'); // This fetches a user structure from the interaction's params, it would be better to use getParam in this use case, but we're showcasing the getUserParam method here.
		const clicker = interaction.user;

		return void interaction.reply({
			content: `hello world!!!!!!!! (clicked by ${clicker}) [made by ${originalUser}]`,
		});
	},
} satisfies ButtonHandler;
```

```bash
disploy dev # test your bot locally with hot-reloading and tunneling
```

```bash
disploy deploy # deploy your bot to Cloudflare Workers
```

The CLI bundles your app by taking in commands and message components and turning them into a single bundle. It accomplishes this by transforming your default exports into an array, creating an App instance, and attaching an adapter for your specified target.

## Planned Features

### Testing

`@disploy/disbench` will be a testing library that will allow you to test your bot in a similar way to how you would test a web app with a mocked Discord API. View the repository [here](https://github.com/Disploy/disbench).

Example usage (this is not final):

```ts
// Disbench demo snippet (fake code)
import { Disbench } from '@disploy/disbench';

const disbench = new Disbench({
	app: 'dist/bot.js',
});

await disbench.setup(); // This will start the bot and start communicating with the framework to "deploy" commands to the mocked API

const echoCommand = disbench.commands.find({ name: 'echo' });

const response = await disbench.interact(echoCommand, {
	options: {
		message: 'Hello World!',
	},
});

expect(response).toEqual('Hello World!');
```

---

Join our [Discord server](https://discord.gg/E3z8MDnTWn) for support and updates!

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