Write Discord bots in Julia. This package is currently the most complete and up-to-date implementation of the Discord API for Julia.
The primary difference between this and other Julia Discord libraries is that it has a separate control plane that primarily works with Discord Gateway. This control plane continuously monitor activities from your Discord server and publish events.
Discord bots run as separate processes. You may operate multiple bots independently of each other. They all share the same events stream from the control plane.
Starting the control requires a simple config file. You can find examples configs in the etc folder of this repo.
using Discorder
serve(config_file_path="etc/dev.toml")
Bot clients can subscribe to the events and register for specific event patterns. For example, an "echo" bot can be written easily as such:
using Discorder
port = 6000
bot = Bot()
register_command_handler!(bot, CommandTrigger(r",echo (.*)")) do client, message, str
create_message(client, message.channel_id;
content="ok, you said: $str",
message_reference=MessageReference(message_id=message.id)
)
end
start(bot, port)
See example
folder for more bot examples.
Previous attempts were great but had problem with runtime connection instabilities and difficulties in keeping up with Discord API changes. Learning from those experiences, the goals of this project includes:
- Ability to update to the latest Discord API easily
- Have a solid control plane for the gateway interface that is error-resilient and can auto-recover from connectivity problems.
- Ability to decouple user code from the control plane, so problems with user code do not necessarily affect the operation of control plane.
- Consistency with Discord API reference. For example, when you find Create Message from the Discord API documentation, you can find the equivalent
create_message
function (lowercase, snake case). - High-level API that makes it easy to develop and operate a Discord bot.
This project is still a work in progress. The followings are high level tasks:
- Discord v10 API support (reconciled in June 2022)
- Gateway connectivity and auto-recovery from connection problems
- System management via control plane
- Event publisher (local channel, file-based, and ZMQ pub/sub)
- High level command/handler API like those in Xh4H Discord.jl
- Gateway resume (it currently opens a new connection during recovery)
- Audit log header (required for certain API calls since v10)
- Slash commands
Xh4H and Chris de Graaf previously implemented the Xh4H/Discord.jl package, but it was never published in the Julia registry for several reasons.
Chris started a new Discord.jl project in 2020 to keep things as simple as possible and minimize extra features in order to maximize maintainability as the Discord API changes. It also aims to be easily extensible, so that packages providing extra features can be written on top of it. However, Chris could not find time to continue working on the project.
@xxxAnn forked Xh4H's Discord.jl package late 2021 in an attempt to update the API to the latest version. The project is called Ekztazy.jl.
Tom forked Chris' project in 2022 in the light of Discord's plan to decommision version 6 of their API. To avoid confusion to Xh4H and Chris' previous implementations, this package has been renamed to Discorder.jl. While this is a fork from Chris' Discord.jl package, there is no plan to upstream changes.