3
14
Fork
You've already forked discord.zig
3
Discord library but in beta/alpha version
  • Zig 100%
Find a file
2025年07月23日 15:35:20 +00:00
src update to zig master (0.15.0-dev.1184+c41ac8f19) 2025年07月23日 16:38:33 +02:00
test fix make ChannelTypes an enum 2025年05月21日 16:54:54 -05:00
.gitignore remove lib and add .gitignore 2024年11月07日 02:30:30 -03:00
build.zig update to zig master (0.15.0-dev.1184+c41ac8f19) 2025年07月23日 16:38:33 +02:00
build.zig.zon update to zig master (0.15.0-dev.1184+c41ac8f19) 2025年07月23日 16:38:33 +02:00
README.md fix readme aknowledging of issues present with the compilation 2025年05月16日 02:04:06 -05:00

Discord.zig

A high-performance bleeding edge Discord library in Zig, featuring full API coverage, sharding support, and fine-tuned parsing

  • Sharding Support: Ideal for large bots, enabling distributed load handling.
  • 100% API Coverage & Fully Typed: Offers complete access to Discord's API with strict typing for reliable and safe code.
  • High Performance: Faster than whichever library you can name (WIP)
  • Flexible Payload Parsing: Supports payload parsing through both zlib and zstd*.
  • Proper error handling
conststd=@import("std");constDiscord=@import("discord");constShard=Discord.Shard;varsession:*Discord.Session=undefined;fnready(_:*Shard,payload:Discord.Ready)!void{std.debug.print("logged in as {s}\n",.{payload.user.username});}fnmessage_create(_:*Shard,message:Discord.Message)!void{if(message.content!=nullandstd.ascii.eqlIgnoreCase(message.content.?,"!hi")){varresult=trysession.api.sendMessage(message.channel_id,.{.content="hi :)"});deferresult.deinit();constm=result.value.unwrap();std.debug.print("sent: {?s}\n",.{m.content});}}pubfnmain()!void{vargpa:std.heap.GeneralPurposeAllocator(.{})=.init;constallocator=gpa.allocator();session=tryallocator.create(Discord.Session);session.*=Discord.init(allocator);defersession.deinit();constenv_map=tryallocator.create(std.process.EnvMap);env_map.*=trystd.process.getEnvMap(allocator);deferenv_map.deinit();consttoken=env_map.get("DISCORD_TOKEN")orelse{@panic("DISCORD_TOKEN not found in environment variables");};constintents=comptimeblk:{varbits:Discord.Intents=.{};bits.Guilds=true;bits.GuildMessages=true;bits.GuildMembers=true;// WARNING:// YOU MUST SET THIS ON DEV PORTAL// OTHERWISE THE LIBRARY WILL CRASHbits.MessageContent=true;break:blkbits;};trysession.start(.{.intents=intents,.authorization=token,.run=.{.message_create=&message_create,.ready=&ready},.log=.yes,.options=.{},.cache=.defaults(allocator),});}

Installation

// In your build.zig fileconstexe=b.addExecutable(.{.name="beluga",.root_source_file=b.path("src/main.zig"),.target=target,// just a suggestion, use .ReleaseSafe.optimize=optimize,// must always be on, hard dependency.link_libc=true,// self-hosted backed is unstable as of today 2025年05月16日, .use_llvm=true,});constdzig=b.dependency("discordzig",.{});exe.root_module.addImport("discord.zig",dzig.module("discord.zig"));

Warning: the library is intended to be used with the latest dev version of Zig.

contributing

Contributions are welcome! Please open an issue or pull request if you'd like to help improve the library.

general roadmap

Task Status
make the library scalable with a gateway proxy
get a cool logo

missing structures

feature Status
components V2
the tags beside ur name

missing events right now

Event Support
voice_channel_effect_send
voice_state_update
voice_server_update

http methods missing

Endpoint Support
Audit log
Automod
Guild Scheduled Event related
Guild template related
Soundboard related
Stage Instance related
Subscription related
Voice related
Webhook related