Skip to content

Commit

Permalink
Update DiscordBot.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Jan 8, 2025
1 parent 5926ffd commit 71385c8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion featured/DiscordBot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function (Scratch) {

let bot_data = '';

class DiscordBot {
getInfo() {
return {
Expand Down Expand Up @@ -275,6 +275,16 @@
}

if (data.op === 10) {
// Start heartbeat
const heartbeatInterval = data.d.heartbeat_interval;
this.heartbeat = setInterval(() => {
this.client.send(JSON.stringify({
"op": 1,
"d": null
}));
}, heartbeatInterval);

// Send initial heartbeat
this.client.send(JSON.stringify({
"op": 1,
"d": null
Expand All @@ -295,6 +305,13 @@
this.client.onerror = (error) => {
console.error('WebSocket error:', error);
};

this.client.onclose = () => {
if (this.heartbeat) {
clearInterval(this.heartbeat);
this.heartbeat = null;
}
};
}

disconnectFromDiscord() {
Expand Down

0 comments on commit 71385c8

Please sign in to comment.