A Discord Bot & REST Library for Nim. Discord API Channel and Dimscord Server for help
Why Dimscord?
The other Nim Discord library (discordnim) has bunch of issues, and it's unmaintained.
Install Nim using choosenim or Nim's website
Install Dimscord via Nimble using nimble install dimscord
or GitHub git clone https://github.com/krisppurg/dimscord
Read the Wiki or Examples for referencing. Maybe even rewrite your bot if you want to switch.
Start coding! Stay up-to-date with the latest Dimscord release and stuff.
import dimscord, asyncdispatch, times, options
let discord = newDiscordClient("<your bot token goes here>")
# Handle event for on_ready.
proc onReady(s: Shard, r: Ready) {.event(discord).} =
echo "Ready as " & $r.user
# Handle event for message_create.
proc messageCreate(s: Shard, m: Message) {.event(discord).} =
if m.author.bot: return
if m.content == "!ping": # If message content is "!ping".
let
before = epochTime() * 1000
msg = await discord.api.sendMessage(m.channel_id, "ping?")
after = epochTime() * 1000
# Now edit the message.
# Use 'discard' because editMessage returns a new message.
discard await discord.api.editMessage(
m.channel_id,
msg.id,
"Pong! took " & $int(after - before) & "ms | " & $s.latency() & "ms."
)
elif m.content == "!embed": # Otherwise if message content is "!embed".
# Sends a message with embed.
discard await discord.api.sendMessage(
m.channel_id,
embeds = @[Embed(
title: some "Hello there!",
description: some "This is description",
color: some 0x7789ec
)]
)
# Connect to Discord and run the bot.
waitFor discord.startSession()
Please note that you need to define -d:ssl
if you are importing httpclient before importing dimscord.
You can use -d:dimscordDebug, if you want to debug.
If you want to use voice then you can use -d:dimscordVoice
, this requires libsodium, libopus, ffmpeg and optionally yt-dlp (by default)