Krognol/discordnim

URL error

Opened this issue · 6 comments

I have error on run example

earn.nim(19)            learn
discord.nim(149)         newShard
asyncdispatch.nim(1656)  waitFor
asyncdispatch.nim(1516)  poll
asyncdispatch.nim(355)   runOnce
asyncdispatch.nim(191)   processPendingCallbacks
asyncmacro.nim(36)       getGateway_continue
json.nim(1199)           getGatewayIter
json.nim(475)            []
tables.nim(165)          []
[[reraised from:
learn.nim(19)            learn
discord.nim(149)         newShard
asyncdispatch.nim(1658)  waitFor
asyncfutures.nim(302)    read
]]
Error: unhandled exception: key not found: url
Async traceback:
  learn.nim(19)           learn
  discord.nim(149)        newShard
  asyncdispatch.nim(1656) waitFor
  asyncdispatch.nim(1516) poll
    ## Processes asynchronous completion events
  asyncdispatch.nim(355)  runOnce
  asyncdispatch.nim(191)  processPendingCallbacks
    ## Executes pending callbacks
  asyncmacro.nim(36)      getGateway_continue
    ## Resumes an async procedure
  json.nim(1199)          getGatewayIter
  json.nim(475)           []
  tables.nim(165)         []
Exception message: key not found: url
Exception type: [KeyError]
Error: execution of an external program failed: 'C:\Users\Rayan\Desktop\workspace\learn\src\learn.exe '
stack trace: (most recent call last)

Works on my end. Can you post your code?

Yes, sure !

import asyncdispatch, discordnim

proc messageCreate(s: Shard, m: MessageCreate) =
    if s.cache.me.id == m.author.id: return
    if m.content == "ping":
        asyncCheck s.channelMessageSend(m.channel_id, "pong")
        
let d = newShard("Bot <Token>")

proc endSession() {.noconv.} =
    waitFor d.disconnect()

setControlCHook(endSession)
d.compress = true
let removeProc = d.addHandler(EventType.message_create, messageCreate)
waitFor d.startSession()
removeProc()

Did you replace <token> with your bots token?

OK! It was a bug coming from me!

I will still do a PR tonight to detail your README for easy use of the library

If not, what can I do to help you

Any help is greatly appreciated!