M1tsumi/Zignal
High-performance Discord API wrapper for Zig with zero dependencies
Zignal brings serious performance gains to Discord bot development. Built entirely in Zig with no external dependencies, it delivers speeds that make Python and JavaScript alternatives look sluggish by comparison.
Performance at a glance:
| Metric | Zignal | Discord.py | Discord.js |
|---|---|---|---|
| Startup Time | 85ms | 1.8s | 950ms |
| Memory Usage | 42MB | 185MB | 95MB |
| API Latency | 38ms | 195ms | 110ms |
| Binary Size | 4.8MB | 52MB+ | 78MB+ |
The difference? Zig's compile-time execution and lack of runtime overhead. No garbage collector pauses, no interpreter warmup, just fast native code.
What you get:
Add Zignal to your build.zig:
.{
.name = "my-bot",
.version = "1.0.0",
.dependencies = .{
.zignal = .{
.url = "https://github.com/M1tsumi/Zignal/archive/refs/tags/v1.0.0.tar.gz",
.hash = "7660f560466d98f7eeceee269b919c7bff8368e1141794f168e8a88ea2709f55",
},
},
}
Then import in your code:
const zignal = @import("zignal");
Alternative: Direct Git Import
const zignal = @import("path/to/zignal/src/root.zig");
Requirements: Zig 0.13.0+ and a Discord bot token.
Here's a basic bot that responds to commands:
const std = @import("std");
const zignal = @import("zignal");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const token = "YOUR_BOT_TOKEN_HERE";
var client = zignal.Client.init(allocator, token);
defer client.deinit();
var gateway = try zignal.Gateway.init(allocator, token);
defer gateway.deinit();
var event_handler = zignal.EventHandler.init(allocator);
defer event_handler.deinit();
try event_handler.onReady(struct {
fn handler(session_id: []const u8, application_id: u64) void {
std.log.info("Bot ready! Session ID: {s}, Application ID: {d}", .{ session_id, application_id });
}
}.handler);
try gateway.connect();
std.log.info("Connected to Discord Gateway");
try gateway.startEventLoop();
}
const std = @import("std");
const zignal = @import("zignal");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var client = zignal.Client.init(allocator, "YOUR_BOT_TOKEN");
defer client.deinit();
const user = try client.getCurrentUser();
defer user.deinit();
std.log.info("Logged in as {s}#{s}", .{user.username, user.discriminator});
}
REST API (1000+ endpoints across 43 modules)
Gateway (Event handling framework)
Voice Support
Guild Management
// Security controls
const security = client.guild_security();
const settings = try security.getGuildSecuritySettings(guild_id);
try security.enableTwoFactorAuthRequirement(guild_id);
// Analytics and insights
const analytics = client.guild_analytics();
const overview = try analytics.getGuildOverviewAnalytics(guild_id, "30d");
// Backup and restore
const backup = try client.createGuildBackup(guild_id);
try client.restoreGuildFromBackup(guild_id, backup);
Monetization
If you're building premium bots, Zignal has you covered with full support for Discord's monetization features:
Interactive Components
Build rich user experiences with polls, threads, buttons, and select menus. The embed builder makes creating beautiful messages straightforward.
The library is organized into modules that mirror Discord's API structure:
| Module | Endpoints | What it does |
|---|---|---|
channels |
25 | Create, modify, and delete channels; manage permissions |
guilds |
45 | Server management, roles, members, bans |
messages |
18 | Send, edit, delete messages; reactions and pins |
users |
12 | User info, DMs, connections |
voice |
12 | Voice connections and audio |
interactions |
15 | Slash commands and components |
Additional modules for advanced features:
| Module | Purpose |
|---|---|
guild_security |
Two-factor auth, security rules |
guild_analytics |
Server metrics and insights |
guild_backups |
Full server backup and restore |
monetization |
Premium features and payments |
See the source code and examples for reference.
# Clone and test
git clone https://github.com/M1tsumi/Zignal.git
cd Zignal
zig build test
# Build examples
zig build examples
# Run a specific example
zig build run-basic-bot
One of Zig's killer features is trivial cross-compilation:
# Linux
zig build -Dtarget=x86_64-linux -Doptimize=ReleaseFast
# Windows
zig build -Dtarget=x86_64-windows -Doptimize=ReleaseFast
# macOS (ARM)
zig build -Dtarget=aarch64-macos -Doptimize=ReleaseFast
Check the examples/ directory for complete working bots:
basic_bot.zig - Simple command handlingmusic_bot.zig - Voice and audio playbackmoderation_bot.zig - Moderation tools and loggingslash_commands.zig - Application command setupenterprise_bot.zig - Production-ready with all featuresFROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY your-bot /usr/local/bin/bot
USER 1000:1000
CMD ["/usr/local/bin/bot"]
[Unit]
Description=Discord Bot
After=network.target
[Service]
Type=simple
User=discord-bot
ExecStart=/usr/local/bin/bot
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Zignal follows Zig's explicit memory management model. If you allocate it, you need to free it:
var user = try client.getCurrentUser();
defer user.deinit();
A few guidelines:
defer right after allocationGeneralPurposeAllocator in debug builds to catch leaksPull requests are welcome. For major changes, open an issue first so we can discuss what you'd like to change.
What we're looking for:
See CONTRIBUTING.md for more details.
Zignal is under active development with core functionality implemented. The foundation is solid and the library builds successfully.
| Component | Status |
|---|---|
| Core Features | Implemented |
| REST Endpoints | Implemented (1000+ across 43 modules) |
| Gateway Framework | Implemented |
| Voice Features | Implemented |
| Advanced Features | Implemented |
| Build System | Working |
| CI Pipeline | Fixed and Passing |
Current focus:
MIT License - see LICENSE for details.
Built with Zig for developers who care about performance.