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.6.1-alpha/mod.ts";
If you only want to use HTTP:
export * from "https://deno.land/x/space@0.6.1-alpha/lib/api/http/mod.ts";
If you only want to use interactions:
export * from "https://deno.land/x/space@0.6.1-alpha/lib/api/interactions/mod.ts";
If you only want to use the Gateway:
export * from "https://deno.land/x/space@0.6.1-alpha/lib/api/websocket/mod.ts";
See the release notes for all available versions.
Getting Started
Simple program to get started:
import {
Client,
GatewayDispatchEvents,
GatewayIntentBits,
Message,
onMessageCreate,
} from "./deps.ts";
const token = prompt("token:");
if (!token) {
throw new Error("bad token");
}
const client = new Client(`Bot ${token}`);
client.gateway.listen(
GatewayDispatchEvents.MessageCreate,
(message) => onMessageCreate(client, message),
(message: Message) => {
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.listen(GatewayDispatchEvents.InteractionCreate, (interaction) => {
if (interaction.data.name === "ping") {
return {
type: InteractionResponseType.ChannelMessageWithSource,
data: { content: "pong" },
};
}
});
server.connect(8080);
See the documentation for reference.