Dfx
A Discord library for effect-ts
Install / Use
/learn @tim-smart/DfxREADME
dfx
A Discord library built on top of effect
- Supports both the gateway and webhooks
- Simple yet powerful abstractions to build Discord bots
Example
import { NodeHttpClient, NodeRuntime, NodeSocket } from "@effect/platform-node"
import { DiscordConfig, Ix } from "dfx"
import { DiscordIxLive, InteractionsRegistry } from "dfx/gateway"
import { Config, Effect, Layer } from "effect"
// Create a layer for the discord services
const DiscordLayer = DiscordIxLive.pipe(
Layer.provide([
DiscordConfig.layerConfig({
token: Config.redacted("DISCORD_BOT_TOKEN"),
}),
NodeHttpClient.layerUndici,
NodeSocket.layerWebSocketConstructor,
]),
)
// Create hello service
const HelloLayer = Layer.effectDiscard(
Effect.gen(function* () {
const registry = yield* InteractionsRegistry
// Create hello command that responds with "Hello!"
const hello = Ix.global(
{
name: "hello",
description: "A basic command",
},
Effect.succeed({
type: 4,
data: {
content: "Hello!",
},
}),
)
// register the command(s) and handle errors
yield* registry.register(
Ix.builder.add(hello).catchAllCause(Effect.logError),
)
}),
).pipe(
// provide discord layer
Layer.provide(DiscordLayer),
)
// Construct the main layer
const MainLive = Layer.mergeAll(
// add your other services here
HelloLayer,
)
// run it
NodeRuntime.runMain(Layer.launch(MainLive))
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
