All Projects → cronokirby → Alchemy

cronokirby / Alchemy

Licence: mit
A discord library for Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Alchemy

Discord.js Menu
💬 Easily create Discord.js v12 embed menus with reactions and unlimited customizable pages.
Stars: ✭ 89 (-14.42%)
Mutual labels:  library, discord
Discordeno
Discord API library for Deno
Stars: ✭ 254 (+144.23%)
Mutual labels:  library, discord
Aegis.cpp
Discord C++ library for interfacing with the API. Join our server:
Stars: ✭ 198 (+90.38%)
Mutual labels:  library, discord
Discord Rpc Csharp
C# custom implementation for Discord Rich Presence. Not deprecated and still available!
Stars: ✭ 282 (+171.15%)
Mutual labels:  library, discord
Discord.io
A small, single-file library for creating DiscordApp clients from Node.js or the browser
Stars: ✭ 511 (+391.35%)
Mutual labels:  library, discord
Sleepy Discord
C++ library for the Discord chat client
Stars: ✭ 459 (+341.35%)
Mutual labels:  library, discord
Nostrum
Elixir Discord Library
Stars: ✭ 274 (+163.46%)
Mutual labels:  library, discord
Discpp
Simplified, but feature rich Discord API wrapper written in modern C++.
Stars: ✭ 31 (-70.19%)
Mutual labels:  library, discord
Discord.jl
The Julia Discord API Wrapper
Stars: ✭ 93 (-10.58%)
Mutual labels:  library, discord
Ahk Rare
My collection of rare and maybe very useful functions
Stars: ✭ 101 (-2.88%)
Mutual labels:  library
Datepicker
A Date Picker with Calendar for iPhone and iPad Apps.
Stars: ✭ 103 (-0.96%)
Mutual labels:  library
Rbb Website
Website to help connect black-owned businesses with consumers and resources
Stars: ✭ 101 (-2.88%)
Mutual labels:  discord
Gifdec
small C GIF decoder
Stars: ✭ 100 (-3.85%)
Mutual labels:  library
Swiftdiscord
Discord API Client for Swift
Stars: ✭ 103 (-0.96%)
Mutual labels:  discord
Kurasuta
A Custom discord.js Sharding Library inspired by eris-sharder.
Stars: ✭ 101 (-2.88%)
Mutual labels:  discord
Manuf
Parser library for Wireshark's OUI database.
Stars: ✭ 103 (-0.96%)
Mutual labels:  library
Mime
The Hoa\Mime library.
Stars: ✭ 100 (-3.85%)
Mutual labels:  library
Timeline Chart View
An android view to represent data over a timeline.
Stars: ✭ 100 (-3.85%)
Mutual labels:  library
Go Execute
Automate CLI commands with Go
Stars: ✭ 104 (+0%)
Mutual labels:  library
Cordless
The Discord terminal client you never knew you wanted.
Stars: ✭ 1,391 (+1237.5%)
Mutual labels:  discord

Alchemy

A Discord library / framework for Elixir.

This library aims to provide a solid foundation, upon which to build a simple, yet powerful interface. Unlike other libraries, this one comes along with a framework for defining commands, and event hooks. No need to mess around with consumers, or handlers, defining a command is as simple as defining a function!

Installation

Simply add Alchemy to your dependencies in your mix.exs file:

def deps do
  [{:alchemy, "~> 0.6.8", hex: :discord_alchemy}]
end

Docs

This is the stable documentation for the library, I highly recommend going through it, as most of the relevant information resides there.

QuickStart

Run mix alchemy.init to generate a template bot file for your project.

Getting Started

The first thing we need to do is define some kind of application for our bot. Thankfully, the Application module encapsulates this need.

defmodule MyBot do
  use Application
  alias Alchemy.Client


  defmodule Commands do
    use Alchemy.Cogs

    Cogs.def ping do
      Cogs.say "pong!"
    end
  end


  def start(_type, _args) do
    run = Client.start("your token here")
    use Commands
    run
  end
end

So we defined what we call a Cog in the Commands module, a cog is simply a module that contains commands. To wire up this command into the bot, we need to use the module, which we do after starting the client. We need to provide a valid return type in start/2, which is why we capture the result of Client.start in a variable.

Now all we need to do to wire up this application, is to add it to our mix.exs:

def application do
  [mod: {MyBot, []}]
end

This makes our bot automatically start when we run our project. Now, to run this project, we have 2 options:

  • use mix run --no-halt (the flags being necessary to prevent the app from ending once our start/2 function finishes)
  • or use iex -S mix to start our application in the repl.

Starting the application in the repl is very advantageous, as it allows you to interact with the bot live.

Using Voice

Alchemy also supports using Discord's Voice API to play audio. We rely on ffmpeg for audio encoding, as well as youtube-dl for streaming audio from sites. Before the Voice API can be used, you'll need to acquire the latest versions of those from their sites (make sure you get ffmpeg with opus support), and then configure the path to those executables in alchemy like so:

# in config.exs
config :alchemy,
  ffmpeg_path: "path/to/ffmpeg",
  youtube_dl_path: "path/to/youtube_dl"

Now you're all set to start playing some audio!

The first step is to connect to a voice channel with Alchemy.Voice.join/2, then, you can start playing audio with Alchemy.Voice.play_file/2, or Alchemy.Voice.play_url/2. Here's an example command to show off these features:

Cogs.def play(url) do
  {:ok, guild} = Cogs.guild()
  default_voice_channel = Enum.find(guild.channels, &match?(%{type: 2}, &1))
  # joins the default channel for this guild
  # this will check if a connection already exists for you
  Alchemy.Voice.join(guild.id, default_voice_channel.id)
  Alchemy.Voice.play_url(guild.id, url)
  Cogs.say "Now playing #{url}"
end

Porcelain

Alchemy uses Porcelain, to help with managing external processes, to help save on memory usage, you may want to use the goon driver, as suggested by Porcelain. For more information, check out their GitHub.

Other Examples

If you'd like to see a larger example of a bot using Alchemy, checkout out Viviani.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].