Draechen
Draechen
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
Thank you for all the help, I've come across a workaround by converting the message into an embed, that works for what I need, and I'll just chalk this up to ... ghosts or something. I sincerely appreciate all the time and effort of everyone giving me a helping hand.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
So, I'd like to hopefully restate the problem with more information, and see if it helps to clarify where I'm at. What reason can anyone think of, that this would work:
let botChannel = client.channels.cache.get(BOT_DRAFT_CHANNEL, true)
let message = `**${format}** draft (${remaining} remaining) - ${draftStatus.usersNotReady.length} ${draftplural} not ready`
botChannel.send({content: message})
let botChannel = client.channels.cache.get(BOT_DRAFT_CHANNEL, true)
let message = `**${format}** draft (${remaining} remaining) - ${draftStatus.usersNotReady.length} ${draftplural} not ready`
botChannel.send({content: message})
and this would post the message in the channel, then the bot would go offline.
let botChannel = client.channels.cache.get(BOT_DRAFT_CHANNEL, true)
let message = `**${format}** draft (${remaining} remaining) - ${draftStatus.usersNotReady.length} ${draftplural} not ready\n${draftStatus.usersNotReady.join(`\t`)}`
botChannel.send({content: message})
let botChannel = client.channels.cache.get(BOT_DRAFT_CHANNEL, true)
let message = `**${format}** draft (${remaining} remaining) - ${draftStatus.usersNotReady.length} ${draftplural} not ready\n${draftStatus.usersNotReady.join(`\t`)}`
botChannel.send({content: message})
Just to assuage fears of values being empty, unassigned or anything else, here is the log of the message variable (in the case where the message fails.
Message variable type string: Message content "LCI draft (3 minutes remaining) - 2 drafters not ready sarkhan6590 draechen"
The underlying code is the exact same thing for both messages, one works, and one does not.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
if I send message as is, it hangs and disconnects if I change nothing else in the code, other than:
let message = `Some folks aren't ready`
let message = `Some folks aren't ready`
if works fine. So I don't understand what the difference is. I tested each of the variables I'm putting in the message and they're all strings, with values.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
That all said, every minute, this function is called:
function checkDrafts(client){
SET_CODES.forEach(draft => {
voteCommands.isvoteReady(vote)
.then( voteStatus => {
if( (voteStatus.usersReady.length + voteStatus.usersNotReady.length) == MAX_POD_SIZE){
//removed this piece in the example because it isn't relevant
}
else{
let notReady = voteStatus.usersNotReady.join('\t')
let format = voteStatus.format.toUpperCase()
let message = `**${format}** ${missingMessage}: ${notReady}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: `${message}`})
}
}
}
}
function checkDrafts(client){
SET_CODES.forEach(draft => {
voteCommands.isvoteReady(vote)
.then( voteStatus => {
if( (voteStatus.usersReady.length + voteStatus.usersNotReady.length) == MAX_POD_SIZE){
//removed this piece in the example because it isn't relevant
}
else{
let notReady = voteStatus.usersNotReady.join('\t')
let format = voteStatus.format.toUpperCase()
let message = `**${format}** ${missingMessage}: ${notReady}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: `${message}`})
}
}
}
}
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
That's the whole function, it gets called every minute, checking the queue in the database to see if the number of voters has been met
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
I don't know what you want me to give you, tbh. I'm sorry for not answering the questions better?
const isDraftReady = (draft) => new Promise((resolve, reject) =>{
"use strict";
console.log(`[isDraftReady] Checking if ${draft} is ready!`)
const userQuery = "SELECT * FROM draft WHERE format = $1;"
const userQueryValues = [draft]
let draftStatus = {
"ready": false,
"format": "",
"usersReady": [],
"usersReadyID": [],
"usersNotReady": [],
"usersNotReadyID": []
}
dbs.voteReady(userQuery, userQueryValues)
.then(queued => {
voteStatus.format = queued[0].format
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
if(voter.status === 'ready'){
voteStatus.usersReady.push(voter.discordname)
voteStatus.usersReadyID.push(voter.discordid)
}
else{
voteStatus.usersNotReady.push(voter.discordname)
voteStatus.usersNotReadyID.push(voter.discordid)
}
})
})
.finally( () => {
if(voteStatus.usersReady.length === MAX_POD_SIZE){
console.log(`Readycheck result: true ${voteStatus.usersReady.length}/${MAX_POD_SIZE}`)
//console.log(voteStatus.usersNotReady)
voteStatus.ready = true;
resolve( voteStatus);
}
else{
console.log(`Readycheck result: false ${voteStatus.usersReady.length}/${MAX_POD_SIZE}`)
//console.log(voteStatus.usersReady)
//console.log(voteStatus.usersNotReady)
voteStatus.ready = false;
resolve(voteStatus);
}
})
.catch(err => {reject(`Error in checking vote table ${err}`)})
})
const isDraftReady = (draft) => new Promise((resolve, reject) =>{
"use strict";
console.log(`[isDraftReady] Checking if ${draft} is ready!`)
const userQuery = "SELECT * FROM draft WHERE format = $1;"
const userQueryValues = [draft]
let draftStatus = {
"ready": false,
"format": "",
"usersReady": [],
"usersReadyID": [],
"usersNotReady": [],
"usersNotReadyID": []
}
dbs.voteReady(userQuery, userQueryValues)
.then(queued => {
voteStatus.format = queued[0].format
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
if(voter.status === 'ready'){
voteStatus.usersReady.push(voter.discordname)
voteStatus.usersReadyID.push(voter.discordid)
}
else{
voteStatus.usersNotReady.push(voter.discordname)
voteStatus.usersNotReadyID.push(voter.discordid)
}
})
})
.finally( () => {
if(voteStatus.usersReady.length === MAX_POD_SIZE){
console.log(`Readycheck result: true ${voteStatus.usersReady.length}/${MAX_POD_SIZE}`)
//console.log(voteStatus.usersNotReady)
voteStatus.ready = true;
resolve( voteStatus);
}
else{
console.log(`Readycheck result: false ${voteStatus.usersReady.length}/${MAX_POD_SIZE}`)
//console.log(voteStatus.usersReady)
//console.log(voteStatus.usersNotReady)
voteStatus.ready = false;
resolve(voteStatus);
}
})
.catch(err => {reject(`Error in checking vote table ${err}`)})
})
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
.format is also in the query.
const isVoteReady = (vote) => new Promise((resolve, reject) =>{
"use strict";
console.log(`[isVoteReady] Checking if ${vote} is ready!`)
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [draft]
let voteStatus = {
"ready": false,
"format": "",
"usersReady": [],
"usersReadyID": [],
"usersNotReady": [],
"usersNotReadyID": []
}
dbs.voteReady(userQuery, userQueryValues)
.then(queued => {
voteStatus.format = queued[0].format
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
if(voter.status === 'ready'){
voteStatus.usersReady.push(voter.discordname)
voteStatus.usersReadyID.push(voter.discordid)
}
else{
voteStatus.usersNotReady.push(voter.discordname)
voteStatus.usersNotReadyID.push(voter.discordid)
}
})
})
const isVoteReady = (vote) => new Promise((resolve, reject) =>{
"use strict";
console.log(`[isVoteReady] Checking if ${vote} is ready!`)
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [draft]
let voteStatus = {
"ready": false,
"format": "",
"usersReady": [],
"usersReadyID": [],
"usersNotReady": [],
"usersNotReadyID": []
}
dbs.voteReady(userQuery, userQueryValues)
.then(queued => {
voteStatus.format = queued[0].format
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
if(voter.status === 'ready'){
voteStatus.usersReady.push(voter.discordname)
voteStatus.usersReadyID.push(voter.discordid)
}
else{
voteStatus.usersNotReady.push(voter.discordname)
voteStatus.usersNotReadyID.push(voter.discordid)
}
})
})
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
voteStatus is the return from a query to the postgres db. and voteStatus.usersNotReady is an array of usernames
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
What should I be looking out for there then? Everything I'm putting in the message variable is a string. Why would one string cause the bot to crash, but not the other?
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
There weren’t any errors in the pm2 logs either. Is there something I’m doing wrong with just sending a message to a channel? I still don’t understand why sending a simple few words works fine, but the other messages don’t.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
I can reproduce it every time now, in the code above. But I start my bot in production with pm2, my dev bot is just running in a command line instance local to my pc.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
Okay, this is blowing my mind a little bit, but it's working now, with one caveat. The places where the bot got disconnected, it was because of the content of the message? For example, the clearing users not ready part. It started working when I switched:
message = `${voteStatus.usersNotReady.length} users not ready removed from the ${voteStatus.format.toUpperCase()} queue, queue is now at ${voteStatus.usersReady.length}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true) .send({content: message})
message = `${voteStatus.usersNotReady.length} users not ready removed from the ${voteStatus.format.toUpperCase()} queue, queue is now at ${voteStatus.usersReady.length}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true) .send({content: message})
to
message = 'Removed inactive users'
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: message})
message = 'Removed inactive users'
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: message})
The same thing with the voters not ready count down (the 5 minute timers) I switched:
let notReady = voteStatus.usersNotReady.join('\t')
let format = voteStatus.format.toUpperCase()
let message = `**${format}** ${missingMessage} *(${remaining} remaining)*: ${notReady}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: `${message}`})
let notReady = voteStatus.usersNotReady.join('\t')
let format = voteStatus.format.toUpperCase()
let message = `**${format}** ${missingMessage} *(${remaining} remaining)*: ${notReady}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: `${message}`})
to:
let message = `${place} notification - Some folks aren't ready`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: `${message}`})
let message = `${place} notification - Some folks aren't ready`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: `${message}`})
and it all works. I have no idea why the message content is breaking it.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
No change in the output in the console. Same 15ish minute pause before it comes back online.
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
Will do!
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
================ Rechecking for active channels (Tuesday, Nov 14, 2023, 10:31 AM) ================ ================ Rechecking for active channels (Tuesday, Nov 14, 2023, 10:31 AM) ================ Hey! 🔥-pod-vote-coordination(1110947498685649046) is no longer active! Readycheck result: false 1/2 Got: false from isvoteReady function [WS => Shard 0] Destroying shard Reason: Got disconnected by Discord Code: 1000 Recover: Reconnect [WS => Shard 0] Connection status during destroy Needs closing: false Ready state: 3 [WS => Shard 0] Connecting to wss://gateway.discord.gg?v=10&encoding=json [WS => Shard 0] Waiting for event hello for 60000ms [WS => Shard 0] Preparing first heartbeat of the connection with a jitter of 0.5097057277951755; waiting 21025ms [WS => Shard 0] Waiting for identify throttle [WS => Shard 0] Identifying shard id: 0 shard count: 1 intents: 38403 compression: none [WS => Shard 0] Waiting for event ready for 15000ms [WS => Shard 0] Shard received all its guilds. Marking as fully ready. Nope, skipping bot message
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
<here's where the pause occurs>
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
================ Rechecking for active channels (Tuesday, Nov 14, 2023, 10:15 AM) ================ ================ Rechecking for active channels (Tuesday, Nov 14, 2023, 10:15 AM) ================ pod-vote-coordination(1110947498685649046) [voteWhosMissing] Sending 3rd who's missing [isvoteReady] Checking if lci is ready! [voteReady] sending query...SELECT * FROM vote WHERE format = $1; Readycheck result: false 1/2 Got: false from isvoteReady function Nope, skipping bot message [voteWhosMissing] Sending 2nd who's missing [isvoteReady] Checking if lci is ready! [voteReady] sending query...SELECT * FROM vote WHERE format = $1; Readycheck result: false 1/2 Got: false from isvoteReady function Nope, skipping bot message [WS => Shard 0] Heartbeat acknowledged, latency of 34ms. ================ Rechecking for active channels (Tuesday, Nov 14, 2023, 10:16 AM) ================ ================ Rechecking for active channels (Tuesday, Nov 14, 2023, 10:16 AM) ================ pod-vote-coordination(1110947498685649046) [WS => Shard 0] Heartbeat acknowledged, latency of 28ms. [isvoteReady] Checking if lci is ready! [voteReady] sending query...SELECT * FROM vote WHERE format = $1; Readycheck result: false 1/2 [RemoveUsers]Sending query DELETE FROM vote WHERE format = $1 and status != 'ready' with lci [votestatusMessage]Sending query..." SELECT setcode, (SELECT CASE WHEN EXISTS ( SELECT COUNT(discordname) FROM vote WHERE lower(format) = lower(dr.setcode)) THEN (SELECT COUNT(discordname) FROM vote WHERE lower(format) = lower(dr.setcode)) ELSE 0 End as queuecount UNION ALL SELECT 0 WHERE NOT EXISTS (SELECT COUNT(discordname) FROM vote WHERE lower(format) = lower(dr.setcode)) ) FROM voteformat dr WHERE active = true with undefined Nope, skipping bot message
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
(as a precursor I haven't strict-moded the other two files, just the votecommands)
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
Here's the full file: draebot.js - https://sourceb.in/qfLtkyu6xR voteCommands.js -https://sourceb.in/nEaiLuV0sj db.js - https://sourceb.in/LbBNNRrNXX
45 replies
DIAdiscord.js - Imagine an app
Created by Draechen on 11/6/2023 in #djs-questions
Bot crashing without any errors
BTW thank you so much for your patience and help as I stumble through all this
45 replies