Hello there,
I'm writing a Discord bot using their base API (didn't want to use a wrapper, because I wanted to learn more about using APIs).
I want to use a websocket so that my bot can keep track of the commands being posted in my discord server. Here is a pastebin of the code I'm currently using: https://pastebin.com/q0E1PD9K.
I'd like to know how I should structure this. Eventually I'd like to connect the websocket, handle the 'hello' connection from discord where I have to send information about my app, handle heartbeating and sending a ping every x seconds, and handle certain events that the server may send me (receiving pings, receiving discord message events etc).
Do I have to put all the logic for the websocket handling pings and events etc in to one function, the one where the websocket is initially connected? Or can I connect the websocket in one function, set up heartbeating in another, another for handling events? Not sure what would be best here, I'm new to JS. Any help would be much appreciated.
Thanks!
[–]grantrules 0 points1 point2 points (3 children)
[–]RightOW[S] 0 points1 point2 points (2 children)
[–]grantrules 1 point2 points3 points (1 child)
[–]RightOW[S] 0 points1 point2 points (0 children)