forked from yuzucchii/discord.zig
fix race condition + readme update
This commit is contained in:
parent
e1e0fcae33
commit
8749925bc3
@ -834,8 +834,8 @@ pub fn handleEvent(self: *Self, name: []const u8, payload: json.Value) !void {
|
||||
};
|
||||
|
||||
// default handler for whoever wants it
|
||||
if (self.handler.any) |anyEvent|
|
||||
try anyEvent(self, payload);
|
||||
//if (self.handler.any) |anyEvent|
|
||||
//try anyEvent(self, payload);
|
||||
}
|
||||
|
||||
pub fn logif(self: *Self, comptime format: []const u8, args: anytype) void {
|
||||
|
@ -17,15 +17,11 @@
|
||||
const std = @import("std");
|
||||
const Discord = @import("discord");
|
||||
const Shard = Discord.Shard;
|
||||
const Intents = Discord.Intents;
|
||||
|
||||
const INTENTS = 53608447;
|
||||
|
||||
var session: *Discord.Session = undefined;
|
||||
|
||||
fn ready(_: *Shard, payload: Discord.Ready) !void {
|
||||
std.debug.print("logged in as {s}\n", .{payload.user.username});
|
||||
// cache demonstration TODO
|
||||
}
|
||||
|
||||
fn message_create(_: *Shard, message: Discord.Message) !void {
|
||||
@ -54,9 +50,21 @@ pub fn main() !void {
|
||||
@panic("DISCORD_TOKEN not found in environment variables");
|
||||
};
|
||||
|
||||
const intents = comptime blk: {
|
||||
var bits: Discord.Intents = .{};
|
||||
bits.Guilds = true;
|
||||
bits.GuildMessages = true;
|
||||
bits.GuildMembers = true;
|
||||
// WARNING:
|
||||
// YOU MUST SET THIS ON DEV PORTAL
|
||||
// OTHERWISE THE LIBRARY WILL CRASH
|
||||
bits.MessageContent = true;
|
||||
break :blk bits;
|
||||
};
|
||||
|
||||
try session.start(.{
|
||||
.intents = intents,
|
||||
.authorization = token,
|
||||
.intents = Intents.fromRaw(INTENTS),
|
||||
.run = .{ .message_create = &message_create, .ready = &ready },
|
||||
.log = .yes,
|
||||
.options = .{},
|
||||
|
Loading…
x
Reference in New Issue
Block a user