krisppurg / dimscord

A Discord Bot & REST Library for Nim.
https://krisppurg.github.io/dimscord/
MIT License
225 stars 20 forks source link

Issue while trying to compile file #12

Closed Technisha closed 4 years ago

Technisha commented 4 years ago

Heya, I'm having an issue trying to compile my code, here is the code:


import dimscord, asyncdispatch, times

let cl = newDiscordClient("my token")

cl.events.on_ready = proc (s: Shard, r: Ready) = # Add Event Handler for on_ready.
  echo "Connected to Discord as " & $r.user

cl.events.message_create = proc (s: Shard, m: Message) = #  Add Event Handler for message_create.
  if m.author.bot: return
  if m.content == "!ping": # if message content is "!ping"
    let before = getTime().utc.toTime.toUnix
    let msg = waitFor cl.api.sendMessage(m.channel_id, "ping?")
    let after = getTime().utc.toTime.toUnix
    asyncCheck cl.api.editMessage(m.channel_id, msg.id, "Pong! took " & $int(after - before) & "ms | " & $s.getPing() & "ms.") # Edit the message as pong! asyncCheck means that it  will only raise an exception if it fails.
  elif m.content == "!embed": # otherwise if content is embed
    asyncCheck cl.api.sendMessage(m.channel_id, embed = ?Embed( # Sends a messge with embed. The '?' symbol is a shorthand for 'some' in options.
      title: ?"Hello there!",
      description: ?"This is a cool embed",
      color: ?5))

waitFor cl.startSession(compress=true)```

And here is the error ```
/data/data/com.termux/files/home/nim_stuff/discord/main.nim(5, 22) Error: type mismatch: got <proc (s: Shard, r: Ready){.gcsafe, locks: 0.}> but expected 'proc (s: Shard, r: Ready): Future[system.void]{.closure.}'```
To compile it I'm doing
```nim c -d:ssl main.nim```
And I've had this issue on my PC too, I'm using the devel branch
krisppurg commented 4 years ago

Replace the handlers with {.async.}, example proc (s: Shard, m: Message) {.async.}. Also, if you do want to compress, install zlib1.so.1.

Technisha commented 4 years ago

Thanks! I'll try it rn

Technisha commented 4 years ago

Doesn't work ;-;

import dimscord, asyncdispatch, times

let cl = newDiscordClient("my token")

cl.events.on_ready = proc (s: Shard, r: Ready) = # Add Event Handler for on_ready.
  echo "Connected to Discord as " & $r.user

cl.events.message_create = proc (s: Shard, m: Message) {.async.} = #  Add Event Handler for message_create.
  if m.author.bot: return
  if m.content == "!ping": # if message content is "!ping"
    let before = getTime().utc.toTime.toUnix
    let msg = waitFor cl.api.sendMessage(m.channel_id, "ping?")
    let after = getTime().utc.toTime.toUnix
    asyncCheck cl.api.editMessage(m.channel_id, msg.id, "Pong! took " & $int(after - before) & "ms | " & $s.getPing() & "ms.") # Edit the message as pong! asyncCheck means that it  will only raise an exception if it fails.
  elif m.content == "!embed": # otherwise if content is embed
    asyncCheck cl.api.sendMessage(m.channel_id, embed = ?Embed( # Sends a messge with embed. The '?' symbol is a shorthand for 'some' in options.
      title: ?"Hello there!",
      description: ?"This is a cool embed",
      color: ?5))

waitFor cl.startSession()

Here is the error


/data/data/com.termux/files/home/nim_stuff/discord/main.nim(5, 22) Error: type mismatch: got <proc (s: Shard, r: Ready){.gcsafe, locks: 0.}> but expected 'proc (s: Shard, r: Ready): Future[system.void]{.closure.}'```
krisppurg commented 4 years ago

You forgot the ready proc one

Technisha commented 4 years ago

Oh :P

Technisha commented 4 years ago

It worked! Thanks! I'ma close this issue now (also i recommend fixing the example because it's kinda broken)