@httpi/client
v1.0.11
Published
A simple HTTP interactions library for Discord with built-in handlers
Downloads
32
Readme
@httpi/client
A type-safe and performant HTTP interactions library for Discord with built-in handlers for TypeScript and JavaScript developers.
Discord server: https://discord.gg/gazktH5y3e
Install using:
# npm
npm i @httpi/client
npm i @httpi/adapter-hyperexpress
# yarn
yarn add @httpi/client
yarn add @httpi/adapter-hyperexpress
# pnpm
pnpm i @httpi/client
pnpm i @httpi/adapter-hyperexpress
Create a standalone client
import { createEvents } from '@httpi/client';
import { createStandaloneClient } from '@httpi/adapter-hyperexpress';
// Under "INTERACTIONS ENDPOINT URL" on https://discord.dev, add your link.
createStandaloneClient({
port: 3000,
publicKey: "public key here",
events: createEvents({
// `commands` should be an array of 'Command'/'CommandWithSubcommands'
// `components` should be an array of 'Component'
commands,
components,
}),
});
Store an array of commands and components separately
Commands
import { Command } from "@httpi/client";
const helpCommand = new Command({
data: {
name: "help",
description: "This is a help command",
},
execute({ respond }) {
respond({
type: 4, // ChannelMessageWithSource
data: {
content: "Hello world!",
},
});
},
});
export const commands = [
helpCommand,
];
Components
import { Component } from "@httpi/client";
const buttonComponent = new Component({
customId: /^button$/,
execute({ respond }) {
return respond({
type: 4, // ChannelMessageWithSource
data: {
content: "Hello world!",
},
});
},
});
export const components = [
buttonComponent,
];
Create commands
import { createCommands } from "@httpi/client";
const result = await createCommands({
id: "discord id here",
token: "token here",
// `commands` should be an array of 'Command'/'CommandWithSubcommands'
commands,
});
console.log(result);
process.exit();
Adapters
If you want to use this library with another HTTP server library, you can use one of these adapters:
- HyperExpress adapter by real2two
- Hono adapter by real2two
- itty-router adapter by real2two
- ElysiaJS adapter by desplmfao
More examples
Not everything in the library is documented in README.md
.
Here are some useful links that has an example to do something that might've not been mentioned above:
Client
Commands
- Create an array of commands
- Create a chat input command
- Create a command with subcommands
- Create a user command
- Create a message command