Read token from file.
This commit is contained in:
parent
5d33830255
commit
512239b986
|
@ -1,4 +1,4 @@
|
||||||
import websocket, asyncnet, asyncdispatch, json, httpClient, strformat, eventdispatcher, eventhandler
|
import websocket, asyncnet, asyncdispatch, json, httpClient, strformat, eventdispatcher, eventhandler, streams
|
||||||
|
|
||||||
type
|
type
|
||||||
DiscordOpCode = enum
|
DiscordOpCode = enum
|
||||||
|
@ -100,12 +100,27 @@ proc startConnection*(client: DiscordClient) {.async.} =
|
||||||
e.msg = "Failed to get gateway url, token may of been incorrect!"
|
e.msg = "Failed to get gateway url, token may of been incorrect!"
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
var bot = DiscordClient(token:
|
var tokenStream = newFileStream("../token.txt", fmWrite)
|
||||||
"TOKEN")
|
var tkn: string
|
||||||
|
if (not isNil(tokenStream)):
|
||||||
|
discard tokenStream.readLine(tkn)
|
||||||
|
tokenStream.close()
|
||||||
|
|
||||||
|
var bot = DiscordClient(token: tkn)
|
||||||
|
|
||||||
registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) =
|
registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) =
|
||||||
let event: ReadyEvent = ReadyEvent(bEvt)
|
let event = ReadyEvent(bEvt)
|
||||||
echo "Ready and connected!"
|
echo "Ready and connected 1!"
|
||||||
|
)
|
||||||
|
|
||||||
|
registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) =
|
||||||
|
let event = ReadyEvent(bEvt)
|
||||||
|
echo "Ready and connected 2!"
|
||||||
|
)
|
||||||
|
|
||||||
|
registerEventListener(EventType.evtMessageCreate, proc(bEvt: BaseEvent) =
|
||||||
|
let event = MessageCreateEvent(bEvt)
|
||||||
|
echo "Message was created!"
|
||||||
)
|
)
|
||||||
|
|
||||||
waitFor bot.startConnection()
|
waitFor bot.startConnection()
|
Reference in New Issue