This is a story that started back in 2022, but I think its a perfect time to reflect on the impact that it has had on my friend group still to this day.
A year or so before COVID, our friend group dispersed across the world - I moved to Vancouver, one friend moved to the UK and another one moved to the United States. The rest of them still lived in Melbourne.
Once COVID hit, like many others, we looked to find a way to keep in contact and still hang out. We have always been a big gaming group (both board game & video games) so moving online seemed like a logical choice. We had always used Discord so we started to ramp up our time there.
The problem
Over the next year, our group chat (in Signal) was drowning in notifications. A mix of general chit chat, talks on the ever changing news of COVID and the most important - when can people play games and chat. It really annoyed me when people would post on "hey anyone wanna play [game] in 15 mins?", for it to be buried in another 5 messages. The message would have to be constantly bumped in Signal before we eventually jumped in a voice chat in our Discord server. My friends were also annoyed that they didn't know we were playing a certain game tonight, for us to go "we talked about it on Signal!". Something had to change.
The solution
I thought, rather than people typing in Signal that they want to play a game in Discord, it would be better for Discord to notify us when someone has joined a voice channel in our server. Now you're probably thinking "Daniel, wouldn't this just be another notification that people would miss?" - you would be right to be skeptical, but I thought that since it was a distinct notification from Discord rather than Signal it would be better.
I went to Discord to find a setting to send a notification to the server when someone joined a voice channel, and I came up with crickets. There was no such thing. Eventually I found that you can write a Discord bot to leverage the on_voice_state_update from discord.py, a Discord API wrapper. So I spun up a new git repo and got to work writing a simple Discord bot. Here is main guts of the bot.
Since on_voice_state_update triggers on when a member joins or leaves a voice channel and if the member muted or deafened - we must check that the before channel is null and the after channel is not null to signify that they have joined a voice channel.
We then get the first text channel of the server so that our bot can send the message to the server. Then we actually send the message to the text channel. I added the delete_after option so that the text channel is not clogged up with all the messages sent from the bot. All we care about is receiving the notification. Finally, I add a record into a postgres table (hosted on Supabase) of the Discord server (guild), the member id and member display name along with a timestamp of when they joined. All this juicy data will come in handy later.
... continue reading