Open javierv98 opened 2 years ago
I have the same problem. Anyone can help?
bump
bump
the repo owner seems to sell a "paid non stopping script" your best guess is to either look into the code to see if you can deal with that, or make a batch script to make it restart every x hours
or: npmjs.com/search?q=discord self
the repo owner seems to sell a "paid non stopping script" your best guess is to either look into the code to see if you can deal with that, or make a batch script to make it restart every x hours
or: npmjs.com/search?q=discord self
Don't pay up. I paid him for the script and he blocked me after that.
The connection should be reestablished after it closed, and for that the "close" message should be handled from the websocket. For an example that keeps working endlessly checkout https://gitlab.com/MathijsBlok/discord-mirror
The connection should be reestablished after it closed, and for that the "close" message should be handled from the websocket. For an example that keeps working endlessly checkout https://gitlab.com/MathijsBlok/discord-mirror
instead of posting an entire repo maybe trying posting the relevant code or a solution
The solution would be to implement the close and error events from the websocket connection in the selfcore code. After +/- 3 hours the socket gets a "close" event and after that no new messages will come through the connection.
An example can be found in the "entire repo" (which actually only are 2 files).
this file is the "client" which connects to discord. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/discord-client.ts
this file is the implementation which creates the client and then saves the messages. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/index.ts
@9xN if you need a working version of this, let me know and i can create an npm package that keeps working :)
The solution would be to implement the close and error events from the websocket connection in the selfcore code. After +/- 3 hours the socket gets a "close" event and after that no new messages will come through the connection.
An example can be found in the "entire repo" (which actually only are 2 files).
this file is the "client" which connects to discord. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/discord-client.ts
this file is the implementation which creates the client and then saves the messages. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/index.ts
@9xN if you need a working version of this, let me know and i can create an npm package that keeps working :)
i actually ended up making my own wrapper shortly after i had seen this repository over a year ago that already does this i only posted my last comment in hopes that you could make your description easier for some of the others having issues in this thread some assistance, as to my solution heres an example;
const WebSocket = require('ws');
let sequence = 0
let session_id = ''
let heartRec = true
let token = 'ur token here'
let socket = 'wss://gateway.discord.gg/?v=9&encoding=json'
const https = require('https')
const identifyPayload = {
"op": 2,
"d": {
"token": "token",
"properties": {
"$os": "linux",
"$browser": "scord",
"$device": "scord"
}
}
}
const heartPayload = {
"op": 1,
"d": "sequence"
}
const resumePayload = {
"op": 6,
"d": {
"token": "token",
"session_id": "session_id",
"seq": "sequence"
}
}
function connect() {
const ws = new WebSocket(socket)
ws.on('open', function() {
console.log("connected")
ws.on('message', function incoming(message) {
evaluate(JSON.parse(message), ws)
});
})
ws.on('close', function(code, reason) {
console.log(`disconnected with code:${code}\nReason: ${reason}`)
heartRec = true
reconnect(ws)
})
}
function evaluate(message, ws) {
const opcode = message.op
switch (opcode) {
case 10:
console.log("hello payload received")
const heartbeat_interval = message.d.heartbeat_interval
heartbeat(heartbeat_interval, ws)
if (session_id)
resume(ws)
else
identify(ws)
break
case 11:
// console.log("heartbeat acknowledged")
heartRec = true
break
case 0:
let t = message.t
sequence = message.s
if (t === 'READY') {
session_id = message.d.session_id
console.log(`event dispatched: ${t}`)
}
if (t === 'MESSAGE_CREATE') {
}
}
break
case 1:
console.log('gateway requesting heartbeat')
heartPayload.d = sequence
ws.send(JSON.stringify(heartPayload))
break
// default:
//console.log(message)
}
}
function heartbeat(interval, ws) {
const timer = setInterval(function() {
if (heartRec) {
heartPayload.d = sequence
ws.send(JSON.stringify(heartPayload))
// console.log("heartbeat sent")
heartRec = false
} else {
console.log("zombied connection , reconecting")
heartRec = true
clearInterval(timer)
reconnect(ws)
}
}, interval)
}
function identify(ws) {
identifyPayload.d.token = token
ws.send(JSON.stringify(identifyPayload))
}
function resume(ws) {
resumePayload.d.token = token
resumePayload.d.session_id = session_id
resumePayload.d.seq = sequence
ws.send(JSON.stringify(resumePayload))
}
function reconnect(ws) {
console.log("disconnecting...")
ws.close()
connect()
}
connect()
The solution would be to implement the close and error events from the websocket connection in the selfcore code. After +/- 3 hours the socket gets a "close" event and after that no new messages will come through the connection. An example can be found in the "entire repo" (which actually only are 2 files). this file is the "client" which connects to discord. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/discord-client.ts this file is the implementation which creates the client and then saves the messages. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/index.ts @9xN if you need a working version of this, let me know and i can create an npm package that keeps working :)
i actually ended up making my own wrapper shortly after i had seen this repository over a year ago that already does this i only posted my last comment in hopes that you could make your description easier for some of the others having issues in this thread some assistance, as to my solution heres an example;
const WebSocket = require('ws'); let sequence = 0 let session_id = '' let heartRec = true let token = 'ur token here' let socket = 'wss://gateway.discord.gg/?v=9&encoding=json' const https = require('https') const identifyPayload = { "op": 2, "d": { "token": "token", "properties": { "$os": "linux", "$browser": "scord", "$device": "scord" } } } const heartPayload = { "op": 1, "d": "sequence" } const resumePayload = { "op": 6, "d": { "token": "token", "session_id": "session_id", "seq": "sequence" } } function connect() { const ws = new WebSocket(socket) ws.on('open', function() { console.log("connected") ws.on('message', function incoming(message) { evaluate(JSON.parse(message), ws) }); }) ws.on('close', function(code, reason) { console.log(`disconnected with code:${code}\nReason: ${reason}`) heartRec = true reconnect(ws) }) } function evaluate(message, ws) { const opcode = message.op switch (opcode) { case 10: console.log("hello payload received") const heartbeat_interval = message.d.heartbeat_interval heartbeat(heartbeat_interval, ws) if (session_id) resume(ws) else identify(ws) break case 11: // console.log("heartbeat acknowledged") heartRec = true break case 0: let t = message.t sequence = message.s if (t === 'READY') { session_id = message.d.session_id console.log(`event dispatched: ${t}`) } if (t === 'MESSAGE_CREATE') { } } break case 1: console.log('gateway requesting heartbeat') heartPayload.d = sequence ws.send(JSON.stringify(heartPayload)) break // default: //console.log(message) } } function heartbeat(interval, ws) { const timer = setInterval(function() { if (heartRec) { heartPayload.d = sequence ws.send(JSON.stringify(heartPayload)) // console.log("heartbeat sent") heartRec = false } else { console.log("zombied connection , reconecting") heartRec = true clearInterval(timer) reconnect(ws) } }, interval) } function identify(ws) { identifyPayload.d.token = token ws.send(JSON.stringify(identifyPayload)) } function resume(ws) { resumePayload.d.token = token resumePayload.d.session_id = session_id resumePayload.d.seq = sequence ws.send(JSON.stringify(resumePayload)) } function reconnect(ws) { console.log("disconnecting...") ws.close() connect() } connect()
Awesome! I had the same idea, and also made my own implementation. I just linked to my code so people may be able to reuse that.
Thanks for sharing your code! I'll incorporate that in my code and create a new NPM package when i have time for that. Maybe that way other people will be able to use that.
The solution would be to implement the close and error events from the websocket connection in the selfcore code. After +/- 3 hours the socket gets a "close" event and after that no new messages will come through the connection. An example can be found in the "entire repo" (which actually only are 2 files). this file is the "client" which connects to discord. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/discord-client.ts this file is the implementation which creates the client and then saves the messages. https://gitlab.com/MathijsBlok/discord-mirror/-/blob/main/src/index.ts @9xN if you need a working version of this, let me know and i can create an npm package that keeps working :)
i actually ended up making my own wrapper shortly after i had seen this repository over a year ago that already does this i only posted my last comment in hopes that you could make your description easier for some of the others having issues in this thread some assistance, as to my solution heres an example;
const WebSocket = require('ws'); let sequence = 0 let session_id = '' let heartRec = true let token = 'ur token here' let socket = 'wss://gateway.discord.gg/?v=9&encoding=json' const https = require('https') const identifyPayload = { "op": 2, "d": { "token": "token", "properties": { "$os": "linux", "$browser": "scord", "$device": "scord" } } } const heartPayload = { "op": 1, "d": "sequence" } const resumePayload = { "op": 6, "d": { "token": "token", "session_id": "session_id", "seq": "sequence" } } function connect() { const ws = new WebSocket(socket) ws.on('open', function() { console.log("connected") ws.on('message', function incoming(message) { evaluate(JSON.parse(message), ws) }); }) ws.on('close', function(code, reason) { console.log(`disconnected with code:${code}\nReason: ${reason}`) heartRec = true reconnect(ws) }) } function evaluate(message, ws) { const opcode = message.op switch (opcode) { case 10: console.log("hello payload received") const heartbeat_interval = message.d.heartbeat_interval heartbeat(heartbeat_interval, ws) if (session_id) resume(ws) else identify(ws) break case 11: // console.log("heartbeat acknowledged") heartRec = true break case 0: let t = message.t sequence = message.s if (t === 'READY') { session_id = message.d.session_id console.log(`event dispatched: ${t}`) } if (t === 'MESSAGE_CREATE') { } } break case 1: console.log('gateway requesting heartbeat') heartPayload.d = sequence ws.send(JSON.stringify(heartPayload)) break // default: //console.log(message) } } function heartbeat(interval, ws) { const timer = setInterval(function() { if (heartRec) { heartPayload.d = sequence ws.send(JSON.stringify(heartPayload)) // console.log("heartbeat sent") heartRec = false } else { console.log("zombied connection , reconecting") heartRec = true clearInterval(timer) reconnect(ws) } }, interval) } function identify(ws) { identifyPayload.d.token = token ws.send(JSON.stringify(identifyPayload)) } function resume(ws) { resumePayload.d.token = token resumePayload.d.session_id = session_id resumePayload.d.seq = sequence ws.send(JSON.stringify(resumePayload)) } function reconnect(ws) { console.log("disconnecting...") ws.close() connect() } connect()
Awesome! I had the same idea, and also made my own implementation. I just linked to my code so people may be able to reuse that.
Thanks for sharing your code! I'll incorporate that in my code and create a new NPM package when i have time for that. Maybe that way other people will be able to use that.
ofcourse you are very welcome!
I keep on running into the issue where the gateway stops receiving messages after 3 hours of being ran. Is there anyway to auto restart or reconnect to the client?