| CARVIEW |
discord-haskell: Write bots for Discord in Haskell
Functions and data types to write discord bots. Official discord docs https://discord.com/developers/docs/reference.
See the project readme for quickstart notes https://github.com/discord-haskell/discord-haskell#discord-haskell-
[Skip to Readme]
Modules
[Index] [Quick Jump]
- Discord
- Discord.Handle
- Discord.Interactions
- Internal
- Discord.Internal.Gateway
- Discord.Internal.Rest
- Discord.Internal.Rest.ApplicationCommands
- Discord.Internal.Rest.ApplicationInfo
- Discord.Internal.Rest.AutoModeration
- Discord.Internal.Rest.Channel
- Discord.Internal.Rest.Emoji
- Discord.Internal.Rest.Guild
- Discord.Internal.Rest.HTTP
- Discord.Internal.Rest.Interactions
- Discord.Internal.Rest.Invite
- Discord.Internal.Rest.Prelude
- Discord.Internal.Rest.ScheduledEvents
- Discord.Internal.Rest.User
- Discord.Internal.Rest.Voice
- Discord.Internal.Rest.Webhook
- Discord.Internal.Types
- Discord.Internal.Types.ApplicationCommands
- Discord.Internal.Types.ApplicationInfo
- Discord.Internal.Types.AuditLog
- Discord.Internal.Types.AutoModeration
- Discord.Internal.Types.Channel
- Discord.Internal.Types.Color
- Discord.Internal.Types.Components
- Discord.Internal.Types.Embed
- Discord.Internal.Types.Emoji
- Discord.Internal.Types.Events
- Discord.Internal.Types.Gateway
- Discord.Internal.Types.Guild
- Discord.Internal.Types.Interactions
- Discord.Internal.Types.Prelude
- Discord.Internal.Types.RolePermissions
- Discord.Internal.Types.ScheduledEvents
- Discord.Internal.Types.User
- Discord.Requests
- Discord.Types
Downloads
- discord-haskell-1.18.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
| Versions [RSS] | 0.5.0, 0.5.1, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 1.0.0, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.6.1, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.9.0, 1.9.1, 1.9.2, 1.10.0, 1.11.0, 1.12.0, 1.12.1, 1.12.2, 1.12.3, 1.12.4, 1.12.5, 1.13.0, 1.14.0, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.15.5, 1.15.6, 1.16.0, 1.16.1, 1.17.0, 1.17.1, 1.18.0 (info) |
|---|---|
| Change log | changelog.md |
| Dependencies | aeson (>=2.0 && <2.3), async (>=2.2 && <2.3), base (>=4.14 && <4.22), base64-bytestring (>=1.1 && <1.3), bytestring (>=0.10 && <0.13), containers (>=0.6 && <0.8), data-default (>=0.7 && <0.9), discord-haskell, emojis (>=0.1.3 && <0.2), hashable (>=1.4.0.0 && <1.6), http-api-data (>=0.4 && <0.7), http-client (>=0.6 && <0.8), iso8601-time (>=0.1 && <0.2), MonadRandom (>=0.5 && <0.7), mtl (>=2.2 && <2.4), network (>=3.0.0.0 && <3.3.0.0), req (>=3.9 && <3.14), safe-exceptions (>=0.1 && <0.2), scientific (>=0.3 && <0.4), text (>=1.2 && <3), time (>=1.9 && <1.15), unliftio (>=0.2 && <0.3), unordered-containers (>=0.2.10.0 && <0.3), websockets (>=0.12 && <0.14), wuss (>=1.1 && <3) [details] |
| Tested with | ghc ==8.10.7, ghc ==9.2, ghc ==9.4, ghc ==9.6, ghc ==9.8, ghc ==9.10, ghc ==9.12 |
| License | MIT |
| Copyright | 2019 Karl |
| Author | Karl |
| Maintainer | ksfish5@gmail.com |
| Uploaded | by yutotakano at 2025-07-05T14:01:16Z |
| Category | Network |
| Home page | https://github.com/discord-haskell/discord-haskell |
| Bug tracker | https://github.com/discord-haskell/discord-haskell/issues |
| Source repo | head: git clone https://github.com/discord-haskell/discord-haskell.git |
| Distributions | NixOS:1.18.0 |
| Reverse Dependencies | 2 direct, 0 indirect [details] |
| Executables | state-counter, rest-without-gateway, gateway, cache, interaction-commands-simple, interaction-commands, ping-pong |
| Downloads | 20718 total (219 in the last 30 days) |
| Rating | 2.5 (votes: 6) [estimated by Bayesian average] |
| Your Rating |
|
| Status | Docs available [build log] Last success reported on 2025-07-05 [all 1 reports] |
Readme for discord-haskell-1.18.0
[back to package description]discord-haskell

Build that discord bot in Haskell! Also checkout the calamity haskell library for a more advanced interface.
Documentation
[installing] [debugging] [creating-bot]
[app-commands] [components] [cache] [embeds] [emoji] [intents] [voice]
[design] [contributing] [todo]
Example
This is an example bot that replies "pong" to messages that start with "ping". Checkout the other examples for things like state management.
{-# LANGUAGE OverloadedStrings #-} -- allows "string literals" to be Text
import Control.Monad (when, void)
import UnliftIO.Concurrent
import Data.Text (isPrefixOf, toLower, Text)
import qualified Data.Text.IO as TIO
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
, discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn ""
} -- if you see OnLog error, post in the discord / open an issue
TIO.putStrLn userFacingError
-- userFacingError is an unrecoverable error
-- put normal 'cleanup' code in discordOnEnd (see examples)
eventHandler :: Event -> DiscordHandler ()
eventHandler event = case event of
MessageCreate m -> when (isPing m && not (fromBot m)) $ do
void $ restCall (R.CreateReaction (messageChannelId m, messageId m) "eyes")
threadDelay (2 * 10^6)
void $ restCall (R.CreateMessage (messageChannelId m) "Pong!")
_ -> return ()
fromBot :: Message -> Bool
fromBot = userIsBot . messageAuthor
isPing :: Message -> Bool
isPing = ("ping" `isPrefixOf`) . toLower . messageContent
Discord Server
Ask questions, get updates, request features, etc in the project discord server: https://discord.gg/eaRAGgX3bK
Official Discord Documentation
This api closely matches the official discord documentation, which lists the rest requests, gateway events, and gateway sendables.
You can use the docs to check the name of something you want to do. For example:
the docs list a Get Channel API path,
which translates to discord-haskell's rest request ADT for GetChannel of type ChannelId -> ChannelRequest Channel.
Open an Issue
If something goes wrong: check the error message (optional: check the debugging logs), make sure you have the most recent version, ask on discord, or open a github issue.