All Projects → aquarial → Discord Haskell

aquarial / Discord Haskell

Licence: other
Haskell library for writing Discord bots

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Discord Haskell

Eris
A NodeJS Discord library
Stars: ✭ 879 (+581.4%)
Mutual labels:  discord-api, bot, discord
Discord.js
discord.js is a powerful Node.js module that allows you to easily interact with the Discord API.
Stars: ✭ 16,432 (+12637.98%)
Mutual labels:  discord-api, bot, discord
Modmail
A feature rich discord Modmail bot
Stars: ✭ 957 (+641.86%)
Mutual labels:  discord-api, bot, discord
Dsharpplus
A .NET Standard library for making bots using the Discord API.
Stars: ✭ 635 (+392.25%)
Mutual labels:  discord-api, bot, discord
Discord Panel
📊 User friendly dashboard/tool for discord bot developpers to manage servers
Stars: ✭ 116 (-10.08%)
Mutual labels:  discord-api, bot, discord
Discordrb
Discord API for Ruby
Stars: ✭ 651 (+404.65%)
Mutual labels:  discord-api, bot, discord
Smorebot
SmoreBot is a fun, lightweight, multipurpose bot packed with features.
Stars: ✭ 51 (-60.47%)
Mutual labels:  discord-api, bot, discord
Xiao
Xiao is a Discord bot coded in JavaScript with discord.js using the Commando command framework. With over 500 commands, she is one of the most feature-rich bots out there. Formerly XiaoBot.
Stars: ✭ 302 (+134.11%)
Mutual labels:  discord-api, bot, discord
Nino
🔨 Advanced and cute moderation discord bot as an entry of Discord's Hack Week!
Stars: ✭ 78 (-39.53%)
Mutual labels:  discord-api, bot, discord
Bot
A Discord bot for all your needs. With memes, utilities, moderation & more, Fire is the only bot you'll need.
Stars: ✭ 79 (-38.76%)
Mutual labels:  discord-api, bot, discord
Discord Bot Client
A patched version of discord, with bot login support
Stars: ✭ 441 (+241.86%)
Mutual labels:  discord-api, bot, discord
Discord.js Menu
💬 Easily create Discord.js v12 embed menus with reactions and unlimited customizable pages.
Stars: ✭ 89 (-31.01%)
Mutual labels:  discord-api, bot, discord
Commando
Official command framework for discord.js
Stars: ✭ 434 (+236.43%)
Mutual labels:  discord-api, bot, discord
Deku
Multi-purpose discord bot built with discord.js
Stars: ✭ 13 (-89.92%)
Mutual labels:  discord-api, bot, discord
Javacord
An easy to use multithreaded library for creating Discord bots in Java.
Stars: ✭ 368 (+185.27%)
Mutual labels:  discord-api, bot, discord
Discord4j
Discord4J is a fast, powerful, unopinionated, reactive library to enable quick and easy development of Discord bots for Java, Kotlin, and other JVM languages using the official Discord Bot API.
Stars: ✭ 973 (+654.26%)
Mutual labels:  discord-api, bot, discord
Nostrum
Elixir Discord Library
Stars: ✭ 274 (+112.4%)
Mutual labels:  discord-api, bot, discord
Disgord
Go module for interacting with the documented Discord's bot interface; Gateway, REST requests and voice
Stars: ✭ 277 (+114.73%)
Mutual labels:  discord-api, bot, discord
Basicbot
A basic example of a Discord Bot written in Python. (discord.py)
Stars: ✭ 73 (-43.41%)
Mutual labels:  discord-api, bot, discord
Client
A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.
Stars: ✭ 84 (-34.88%)
Mutual labels:  discord-api, bot, discord

discord-haskell Build Status Hackage version

Build that discord bot in Haskell! Also checkout the calamity haskell discord library for a more advanced interface than discord-haskell.

This is an example bot that replies "pong" to messages that start with "ping".

{-# LANGUAGE OverloadedStrings #-}  -- allows "string literals" to be Text

import Control.Monad (when)
import Data.Text (isPrefixOf, toLower, Text)
import qualified Data.Text.IO as TIO

import UnliftIO

import Discord
import Discord.Types
import qualified Discord.Requests as R

-- | Replies "pong" to every message that starts with "ping"
pingpongExample :: IO ()
pingpongExample = do userFacingError <- runDiscord $ def
                                            { discordToken = "Bot ZZZZZZZZZZZZZZZZZZZ"
                                            , discordOnEvent = eventHandler }
                     TIO.putStrLn userFacingError

eventHandler :: Event -> DiscordHandler ()
eventHandler event = case event of
       MessageCreate m -> when (not (fromBot m) && isPing (messageText m)) $ do
               _ <- restCall (R.CreateReaction (messageChannel m, messageId m) "eyes")
               threadDelay (4 * 10^6)
               _ <- restCall (R.CreateMessage (messageChannel m) "Pong!")
               pure ()
       _ -> pure ()

fromBot :: Message -> Bool
fromBot m = userIsBot (messageAuthor m)

isPing :: Text -> Bool
isPing = ("ping" `isPrefixOf`) . toLower

Installing

discord-haskell is on hosted on hackage at https://hackage.haskell.org/package/discord-haskell,

In stack.yaml

extra-deps:
- emoji-0.1.0.2
- discord-haskell-VERSION

In project.cabal

executable haskell-bot
  main-is:             src/Main.hs
  default-language:    Haskell2010
  ghc-options:         -threaded
  build-depends:       base
                     , text
                     , discord-haskell

For a more complete example with various options go to Installing the Library wiki page

Also take a look at Creating your first Bot for some help setting up your bot token

Emoji

For single character Emoji you can use the unicode name ("eyes", "fire", etc).

For multi-character Emoji you must use the discord format. Type \:emoji: into a discord chat and paste that into the Text

For example 👍:skin-tone-3: is "👍\127997". A custom emoji will look like <name:id_number> or name:id_number.

See examples/ping-pong.hs for a CreateReaction request in use.

Embeds

Embeds are special messages with boarders and images. Example embed created by discord-haskell

The Embed record (and sub-records) store embed data received from Discord.

The CreateEmbed record stores data when we want to create an embed.

CreateEmbed has a Default instance, so you only need to specify the fields you use:

_ <- restCall (R.CreateMessageEmbed <channel_id> "Pong!" $
        def { createEmbedTitle = "Pong Embed"
            , createEmbedImage = Just $ CreateEmbedImageUpload <bytestring>
            , createEmbedThumbnail = Just $ CreateEmbedImageUrl
                    "https://avatars2.githubusercontent.com/u/37496339"
            })

Uploading a file each time is slow, prefer uploading images to a hosting site like imgur.com, and then referencing them.

Limitations

The following features are not implemented:

  • Voice & Audio
  • Authenticating with a user token

Debugging

Always print the userFacingError Text returned from runDiscord. I use this to record errors that cannot be recovered from.

If something else goes wrong with the library please open an issue. It is helpful, but not always necessary, to attach a log of what's going on when the library crashes.

Assign a handler to the discordOnLog :: Text -> IO () to print info as it happens. Remember to remove sensitive information before posting.

Getting Help

Official discord docs

For a list of rest requests, gateway events, and gateway sendables go to the official discord documentation

The rest requests line up very closely. The documentation lists Get Channel and discord-haskell has GetChannel :: ChannelId -> ChannelRequest Channel. Same for gateway Events.

Examples

The examples were crafted to display a variety of use cases. Read them with care.

Open an Issue

For deeper questions about how the library functions, feel free to open an issue.

Discord server

Coming sometime!

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].