A collection of fast, scalable, low-level Deno modules for interacting with the Discord API.
Repository
Current version released
4 years ago
Space
A low-level Deno module for interacting with Discord.
Features
- 100% coverage over Discord’s HTTP and websocket APIs.
- Secure by default. Client-side checks prevent
4xx
s from occuring. - Written purely in TypeScript to guarantee type safety.
- Built-in utilities such as event logging and custom caching.
Install
export * from "https://deno.land/x/space@0.7.0-alpha/mod.ts";
If you only want to use HTTP:
export * from "https://deno.land/x/space@0.7.0-alpha/lib/api/http/mod.ts";
If you only want to use interactions:
export * from "https://deno.land/x/space@0.7.0-alpha/lib/api/interactions/mod.ts";
If you only want to use the Gateway:
export * from "https://deno.land/x/space@0.7.0-alpha/lib/api/websocket/mod.ts";
See the release notes for all available versions.
Getting Started
Simple program to get started:
import { Client, GatewayIntentBits, onMessageCreate } from "./deps.ts";
const token = prompt("token:");
if (!token) {
throw new Error("bad token");
}
const client = new Client(`Bot ${token}`);
for await (const [data, shard] of client.gateway.listen("MESSAGE_CREATE")) {
const message = await onMessageCreate(client, data);
if (message.content === "!ping") {
client.rest.createMessage(message.channelID, {
content: "pong!",
});
}
}
client.connect({
intents: GatewayIntentBits.GUILD_MESSAGES,
});
Simple interactions program:
import { InteractionResponseType, Server } from "./deps.ts";
const publicKey = prompt("public key:");
if (!publicKey) {
throw new Error("bad public key");
}
const server = new Server(publicKey);
server.connect(8080);
for await (const [interaction, respond] of server) {
if (interaction.data.name === "ping") {
respond({
type: InteractionResponseType.ChannelMessageWithSource,
data: { content: "pong" },
});
}
}
See the documentation for reference.