https://github.com/tim-smart/dfx
A Discord library for effect-ts
https://github.com/tim-smart/dfx
Last synced: 3 months ago
JSON representation
A Discord library for effect-ts
- Host: GitHub
- URL: https://github.com/tim-smart/dfx
- Owner: tim-smart
- License: mit
- Created: 2022-03-14T21:49:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-02-20T03:26:00.000Z (4 months ago)
- Last Synced: 2026-02-20T07:36:35.817Z (4 months ago)
- Language: TypeScript
- Size: 6.1 MB
- Stars: 111
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# dfx
[](https://discord.gg/dtR2Mtu66Q)
A Discord library built on top of effect
- Supports both the gateway and webhooks
- Simple yet powerful abstractions to build Discord bots
## Example
```typescript
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))
```