#discord_gleam, a discord bot library for gleam (duh)
1 messages Β· Page 1 of 1 (latest)
awesome :0
Update: can recive packets from discord, and maintan a connection with the gateway
code for the test:
import discord_gleam
import discord_gleam/event_handler
import logging
pub fn main(token: String) {
logging.configure()
logging.set_level(logging.Info)
discord_gleam.run(token, [event_handler])
}
fn event_handler(packet: event_handler.Packet) {
case packet {
event_handler.ReadyPacket(ready) -> {
logging.log(logging.Info, "Logged in as " <> ready.d.user.username)
}
event_handler.MessagePacket(message) -> {
logging.log(
logging.Info,
"Received message: '"
<> message.d.content
<> "' from "
<> message.d.author.username,
)
}
_ -> Nil
}
}
A discord bot library im working on (status: can read events)
Only the following events tho: READY, MESSAGE_CREATE
Update: Can send messages
Which means basic commands
A discord bot library im working on (status: basic commands)
That's a pretty cool project!
thanks :D
a little snippet: ```swift
let embed1 =
message.Embed(
title: "Embed Title",
description: "Embed Description",
color: 0x00FF00,
)
discord_gleam.send_message(bot, message.d.channel_id, "Embed!", [
embed1,
])
Some docs π₯ https://github.com/Cyteon/discord_gleam/wiki
a lil check list on the main readme for what is done n what is coming would be neat :) /suggestion
sure
I injured my arm, so development might be stale for a week
ouch, get well soon tho!
thanks :D
Wish you a quick recovery!
ohh nice, I'm very much looking forward to a gleam discord lib. Glyph (https://discord.com/channels/768594524158427167/1221268662195851456) looks promising too, but I'm having an issue, that I'm not sure how to resolve.
thanks
its working rn for basic commands
examples includes ban/kick/embed/pingpong
awesome, I'm looking forward to slash commands
Update v0.0.3:
Added message delete event to packets
Added message deleting + example for it
Fixed some on examples
My only request in any discord bot library in a typed language: typed snowflakes
typed snowflakes?
a large amount of libraries just have one "snowflake" type
so it's easy to mess them up and pass them incorrectly
wonder how much this breaks
nothing broke
interesting
Pushed commit that changes all ids to snowflakes
I've been a fan of typeIDs recently. https://github.com/jetify-com/typeid
+1 but discord uses it's own thing
yeah i know. Just had to think of it because I added it to https://github.com/rvcas/ids recently
Possibly adding slash cmds rn :)
options dosent work in "interaction_create" event
so those cant be used
this is very bare bones and needs lots of work too

A discord bot library im working on (status: basic commands + bare bones slash cmds)
@wintry jay Hi! I like your library and I was hoping that I could help contribute a bit to it.
I made one PR for using env vars for client ID in test, was hoping you could take a look at it π
https://github.com/Cyteon/discord_gleam/pull/2
The client ID was hard-coded in.
sure
great!
Thank you!
i will add a function to delete slash cmds
so u can delete those u dont use anymore
or, a function to remove all actually
so can u just call that before registering cmds
nice!!
dies
@dusky relic i requested some changes on your PR
Pushed v0.0.5 to hex
Adding in a cache now
So you can get deleted messages and edited ones
also to speed it up
gleam feels so gleam after not using it for a while
this code feels bad
but it works ig
need to find some of my silly issues tho
π
working on intents now
Intents appear to be working
current only intents message_content and guild_messages
as any other would be useless atm
big fan of this library so far. does it support sending direct messages to users? i canβt tell from the docs.
I can add that today
Sorry i didnt notice your msg before now π
Working on it
you can see how i solved it myself here https://github.com/drewolson/bridgebot/blob/main/src/bridgebot/discord.gleam#L41
it was cool i had the tools to do it myself
oo fire
:D
btw, if you are using default_intents(), i renamed the function to default() in v0.2.2
works like a charm
Yayyy
FYI, my websocket connection is disconneted every 30 minutes - 2 hours
i believe it's because the heartbeat code is incorrect
i think the right approach is to use process.send_after rather than repeatedly
but i'll need to poke around at it a bit
this is my current workaround https://github.com/drewolson/bridgebot/blob/703a1abf9db307e4bbb6398d58e354dfbcc05cee/src/bridgebot/discord.gleam#L105-L127
oh thats odd
ill take a look at that
I fixed sequence being 0, not sure if that will fix disconnecting tho
ill keep it running for a while to see
btw, up to v0.1.0 i wasnt following semver correctly, my brain was prob lagging
but from then (we are currently at v0.2.4) i have been doing it correctly π
v0's are exempt from semver, thats why you have to type the notice to publish them
yeahh, but still smart to atleast partially follow it
we encourage folks to publish v1's when they want to publish a package, theres no problem hasving major bumps!
i see
i'm trying to get my friends less scared to do major version bumps as they have a habit of doing breaking changes on patch versions π
π
Implemented options in slash cmds, example: https://github.com/Cyteon/discord_gleam/blob/main/examples/slash_commands.gleam
FYI i'm seeing errors on this line https://github.com/Cyteon/discord_gleam/blob/main/src/discord_gleam/ws/event_loop.gleam#L32
INFO Last restart at: 2025-05-22T19:06:44.238Z
INFO Running...
EROR oh nyo, discord closed websocket :c
INFO websocket go bye bye
runtime error: let assert
Pattern match failed, no pattern matched the value.
unmatched value:
Error(ErlangError("badarg"))
stacktrace:
discord_gleam/ws/event_loop.main src/discord_gleam/ws/event_loop.gleam:32
possibly creating an ETS table that already exists with the name "State"?
I see Last restart at: 2025-05-22T19:06:44.238Z - are you restarting your bot programatically?
There doesn't seem to a uset.delete at the end of the main function in the lib
yes, because it keeps crashing
Then what I said seems likely fme
did you figure it out?
or is it still crashing randomly :/
im going to fix some of my wack code then publish 1.0.0
OO
hhhh i totally didnt forget this
implementing rn
did u fix this?
yep, added it
having some issues determing the disconnect code when disconnected from the websocket
should i reconnect every time, unless it was really short since last reconnect? or just only reconnect on reconnect packet
Anyone has any opinion on what i should do before merging v1 onto main and publishing v1?
List of changes alr done: https://github.com/Cyteon/discord_gleam/pull/11/files
Branch: https://github.com/Cyteon/discord_gleam/tree/v1
(imo i should publish v1, then add more intents in future versions)
Imo with you having the "Yeah, you can make a basic and usable bot with this" stuff in, it wouldn't hurt to go ahead and do v1, then expand on it from there.
Agreed
pushing v1 now
time to just implement a lot of gateway events π₯
added CHANNEL_CREATE, CHANNEL_DELETE and CHANNEL_UPDATE
Did anyone encounter this at startup (one of the examples):
EROR Disconnected after too short time, not reconnecting
EROR websocket go bye bye
is this maybe a permissions issue? or something else?
π does it really say 'go bye bye'
lool
Can you try to switch the logging level to Debug and post the entire log?
Ahh didn't see that hah
DEBG Requesting gateway
DEBG Creating builder
DEBG Calling user initializer
DEBG Builder init
DEBG Attempting handshake to https://gateway.discord.gg/?v=10&encoding=json
DEBG Making request to gateway.discord.gg at 443
DEBG Sent upgrade request, waiting 5000
DEBG Handshake successful
DEBG WebSocket process ready to start receiving
DEBG Gateway text msg: {"t":null,"s":null,"op":10,"d":{"heartbeat_interval":41250,"_trace":["[\"gateway-prd-us-east1-b-0b66\",{\"micros\":0.0}]"]}}
DEBG Gateway text msg: {"t":null,"s":null,"op":10,"d":{"heartbeat_interval":41250,"_trace":["[\"gateway-prd-us-east1-b-0b66\",{\"micros\":0.0}]"]}}
DEBG WebSocket closing: "Disallowed intent(s)."
DEBG The webhook was closed
EROR Disconnected after too short time, not reconnecting
EROR websocket go bye bye
so i have the incorrect permissions for the bot?
Enable the message content intent in the bot settings on the discord dev portal
Its under "Privileged Gateway Intents"
it works, thanks! π
Epic
I thought I'd update the deps, but oh what a rabbit hole π https://github.com/cyteon/discord_gleam/pull/15
holy
would it be possible to have bravo just use < 1.0.0 gleam_erlang instead?
let me check
i seem to have it almost working now, just this:
error: Type mismatch
ββ /Users/dvic/Development/discord_gleam/src/discord_gleam/ws/event_loop.gleam:71:13
β
71 β loop: fn(state, msg, conn) {
β ββββββββββββββ^
72 β β case msg {
73 β β stratus.Text(msg) -> {
74 β β logging.log(logging.Debug, "Gateway text msg: " <> msg)
Β· β
191 β β }
192 β β },
β β°βββββββ^
Expected type:
fn(State, stratus.Message(String), stratus.Connection) -> stratus.Next(State, String)
Found type:
fn(State, stratus.Message(String), stratus.Connection) -> actor.Next(State, a)
and this
todo
// process.new_selector()
// |> process.selecting_process_down(process.monitor(pid), function.identity)
// |> process.select_forever
(with all the deps bumped)
epic
nope, it's all connected haha, so the best is just to push through and update everything to latest
fair
i've updated the description π
yeah, these are the PRs of the deps that need to be merged
max and rawhat shouldn't take too long, but bravo hasn't been updated in like a year
yeah and i noticed that bravo also changed the api on the main branch, as part of the next 5.x release, anyways, i fixed all tell issues on the PR: https://github.com/cyteon/discord_gleam/pull/15/commits/493d61669329e451b326ff16380447652bf79d89
everything compiles and the test bot is running
me when i am adding ban event but end up fixing how errors are done in the event handler (the channel update event isnt updated to new yet)
now it will be way easier to debug and stuff
ban and unban events work (ignore the empty messages, those are embed-only messages from other bots)
π
published v1.2.0
discord_gleam, a discord bot library for gleam (duh)
btw im still working on this, but a little slower as i have a job for the next two weeks, and for the past week
Added the GUILD_ROLE_CREATE, GUILD_ROLE_UPDATE and GUILD_ROLE_DELETE gateway events
currently working on the dev branch: https://github.com/cyteon/discord_gleam/tree/dev
just implementing a bunch of gateway stuff
they need to update to gleam_erlang 1.0.0
oh i see
discord_gleam is using 0.34.0
yeah im on gleam 1.11.1
gleam version doesn't matter
oh
gleam_erlang is a package
you can pin it in your gleam.toml for now
[dependencies]
gleam_erlang = "0.34.0"
that seems really outdated
oh
well i updated
same error...
i just ran "gleam deps download"
is that correct?
Sorry, im new
gleam deps update after pinning it
oh
dw ^.^
now i need rebar3
yeah
does gleam not install dependencies of dependencies?
i have to add them all myself?
rebar3 is the erlang build tool
yeah, i think i've seen people use the non-minimal one for nix as well
yeah it didn't like this version
while you're there make sure you have erlang installed too
i think it's borked on unstable rn
nah, i was just looking at nix 25.05
#1395043705269784698 message
yay :D
if u have any questions feel free to ping me and you will prob get a question instantly, or whitin 12 hours (if im sleeping)
i should check this thread more often tho, so i see messages where im not pinged
@kindred sundial one of your prs got closed
But the library was updated
So ig make the next draft pr use that version and mark ready for review?
saw it, will try to get to it this weekend!
awesome!
unfortunately, we're still blocked by https://github.com/maxdeviant/glenvy/pull/12, which is waiting on release of https://github.com/hayleigh-dot-dev/nibble/commit/0e67e2916313c4819e6396f2ecc9244733d41193
@foggy jay
appreciate that this might be a priority for you but pinging me at 08:30am is probably not the play
Then ignore it. I don't understand why this is such a big issue.
I just wanted to make sure you were aware of the situation.
nibble got an update!
nice!
I've bumped the PR, now we're only blocked by https://github.com/Michael-Mark-Edu/bravo/pull/5
fire
Maybe you should consider some alternatives?
What about this one? https://hexdocs.pm/booklet/index.html
A simple in-memory cache using ETS tables or mutable references.
i think either switching library or writing your own FFI to ETS is the best course of action atp
I'll take a look at booklet once I'm home from my trip tmrw
ended up using booklet and it works great
closed as changing from bravo to booklet alloewd me to update everything else, so now we are updated as of https://github.com/cyteon/discord_gleam/commit/31f53fc4dd58daf415819bbaeceee7eb0ceb9878 / v1.5.0
fixing the gh workflow then releasing 1.5.0
released :D
nice!!!!
cause school has started for me development will be slow, but i will still try to find time for it
i hope to implement more stuff this weekend
nothing this weekend, cause i gota lot of stuff to do and im going to spend the little time i have to relax
but i hope to do it tmrw cause i dont have that much school then
what do yall feel like its most important for me to add the soonest?
tbh looking at your feature set, you've done so much since I last checked it out.
implemented close codes, makes it way easier to debug if you are disconnected
nit: Discord should be capitalised in the err msg π
really good job with everything here! I haven't had a chance to use it for a while but it seems like you're making amazing progress
I'm pretty sure it's "Discord Developer Portal" if we're going there
fairr, ill fix that
Hi!
I'm tryig to use this
and I'm not sure if the GuildMemberAddPacket works
with intents set to all on both the developer portal and the code
fn event_handler(bot, packet: event_handler.Packet) {
case packet {
event_handler.GuildMemberUpdatePacket(member) -> {
echo "Guild member add packet received"
Nil
}
}
}
this has no output
Nvm i fixed it
awesome library though!
@deep cargo I've noticed a pattern of you asking a question and then immediately figuring it out. Have you ever considering getting a desk rubber duck? Rubber duck debugging is quite useful π
LOL, yeah.. its some sort of curse
I have a rubber duck, but its noisy, and I don't like making noise
i think its good π if someone has a similar problem in the future they can see you figured it out and ask you
Even better with a quick summary of the solution :)
it was me not using intents when I configured the bot
i was using the code from the docs first page
I don't want to dissuade them from posting! Just something I do (but without having an actual rubber duck) and it works for me :3
Just one note, ```
case interaction.d.data.name {
"ping" -> {
case interaction.d.data.options {
option.Some(options) -> {
case list.first(options) {
Ok(option) -> {
let value = case option.value {
interaction_create.StringValue(value) -> value
_ -> "unexpected value type"
}
seems like a lot of cases...
for slash commands
there are ways to refactor your code to make it less nested
you can extract things out to their own functions
you can make use of use
you can make use of pipelines
without the full context it'd be hard to show you a possible refactor
instead of list.first, pattern match on the list items in the option.Some(...)
I'd pull each command into a function, so ping would be its own thing
Also, you can match on the option like Some([option, ..]) ->
But this is getting more into general gleam advice, so let's not further hijack the thread
Just wanted to share, i made a VERY SIMPLE discord bot (like only !ping pong and welcome messages bot with this: https://github.com/unsecretised/clanker-discordbot
GitHub
A gleam discord bot for the encoding decoded discord server - unsecretised/clanker-discordbot
the clanker
yes
made a few small PRs to discord_gleam π
tysm, ill check them out asap
hi
does the new version of this work?
the readme is very outdated
but i think i did it right based on the tests
maybe im using the wrong token or clientid?
hmmm
I can add commands and everything
that works
but the bot never goes online
@wintry jay hello π
I was wondering if you'd be able to help diagnose this warning i keep getting
it should
uh my fault, ill get that fixed
can you send the full warning?
I'll try getting that tonight
WARN #(charlist.from_string("Actor discarding unexpected message: ~s"), [charlist.from_string("Ssl(Sslsocket(//erl(#Port<0.6>), //erl(<0.136.0>), //erl(<0.135.0>), GenTcp, TlsGenConnection, //erl(#Ref<0.3990994764.2383806473.93114>), Undefined), <<129, 126, 0, 128, 123, 34, 116, 34, 58, 110, 117, 108, 108, 44, 34, 115, 34, 58, 110, 117, 108, 108, 44, 34, 111, 112, 34, 58, 49, 48, 44, 34, 100, 34, 58, 123, 34, 104, 101, 97, 114, 116, 98, 101, 97, 116, 95, 105, 110, 116, 101, 114, 118, 97, 108, 34, 58, 52, 49, 50, 53, 48, 44, 34, 95, 116, 114, 97, 99, 101, 34, 58, 91, 34, 91, 92, 34, 103, 97, 116, 101, 119, 97, 121, 45, 112, 114, 100, 45, 97, 114, 109, 45, 117, 115, 45, 101, 97, 115, 116, 49, 45, 100, 45, 108, 107, 116, 56, 92, 34, 44, 123, 92, 34, 109, 105, 99, 114, 111, 115, 92, 34, 58, 48, 46, 48, 125, 93, 34, 93, 125, 125>>)")])
This is those bytes as a string btw
{
"t": null,
"s": null,
"op": 10,
"d": {
"heartbeat_interval": 41250,
"_trace": [
[
"gateway-prd-arm-us-east1-d-lkt8",
{ "micros": 0.0 }
]
]
}
}
tysm
imm not sure why this is happening, and im unable to recreate it
Hm rip
are you using the latest version?
Yeah
hm
