Bot crashing without any errors

Good afternoon! I apologize if this isn't the correct forum for my question, but my bot seems to be going offline after one particular command has been triggered. It processes through the on message create, posts the message in the channel (along with sending a couple of DMs to the users who triggered that command), but then it hangs and goes offline without any error message or anything indicating a problem. Here is the section where everything occurs:
const startReadyCheckSequence = (vote, client) => { message = "\n It's time to vote! Reply !vote yes|no in the channel or respond to the DM with your vote. You have 5min to respond" vote.queue.forEach(user=> {console.log(Sending message to ${user.username}`) user.send({content: message}) }) sendMessageToVoteChannel(client,mentionUsers(vote) + message) vote.ready = true console.log ("BEFORE SET TIMEOUT") setTimeout(removeNotReadyUsers, 300000, vote, client) };
and here is the command parser section that calls it:
}else if ( primaryCommand === "join" ){ updateStatus() if (arguments[0] === undefined){ client.channels.fetch(msgChannelID, true) .then(channel=> channel.send("Please provide a valid vote code")) return; } if (!VOTE_CODES.includes(arguments[0].toLowerCase())){ client.channels.fetch(msgChannelID, true) .then(channel=> channel.send("Please provide a valid vote code")) return; } ///TODO clean this up var vote = chosenVote(arguments) VoteCommands.addToQueue(receivedMessage, vote, client)
10 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Draechen
DraechenOP14mo ago
And finally, what links the two togther.
const addToQueue = (receivedMessage, vote, client) => { if (vote.queue.length == vote.MIN_VOTE_SIZE){ receivedMessage.channel.send(vote.name +" is in progress of voting") return; } if (vote.queue.includes(receivedMessage.author)){ receivedMessage.channel.send("You are already in the queue") return; } const userName = receivedMessage.author.username vote.queue.push(receivedMessage.author) receivedMessage.channel.send(userName + ' was added to the queue ' + vote.queueCount())
//status.updateStatus() if (vote.queue.length == MIN_VOTE_SIZE){ startReadyCheckSequence(vote, client); }
};
-- [email protected] node -v v18.16.0 If it helps for detail the join command works fine without hanging until the queu size is met, then when the vote is triggered, that's when it hangs, after processing the DMs and sending the message to the channel (the min_vote_size is set to 8)
duck
duck14mo ago
first, please determine exactly which line is hanging which is to say, you'll want to find exactly which line is the last to execute properly
d.js docs
d.js docs14mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
client
.on("debug", console.log)
.on("warn", console.log)
- Note: if you initialize your Client as bot or other identifiers you need to use these instead of client - If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
duck
duck14mo ago
this may also help
Draechen
DraechenOP14mo ago
Thank you for that, I've combed through everything I can, and the only thing I can think of that would be causing the issue is sending the DMs to users, does Discord throw a bot offline for sending out (at max 8) DMs in rapid succession? As soon as that happens, the bot hangs, then goes offline completely. No error, nothing.
Draechen
DraechenOP14mo ago
Here is the last part of the log file: It sends 2 DMs Sends a console log ("BEFORE SET TIMEOUT") Then the message.create event skips the three messages the bot posted in the bot channel on the server. Then, after sitting there for about 150 seconds, it goes offline
No description
Draechen
DraechenOP14mo ago
Update: I've confirmed the DMs is not the issue, it's the posting of a message tagging users.
const mentionUsers = (vote) => new Promise ((resolve, reject) => {
var message_string = ""
var userQuery = "SELECT * FROM vote WHERE format = $1;"
userQueryValues = [vote]
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
queued.forEach(voter =>{
message_string = message_string.concat(' ', "<@"+voter.discordid+">")
})
})
.finally( () =>{
resolve(message_string)
})
.catch((err) => {console.error(`Error building vote message: ${e}`)})
})

mentionUsers(vote)
.then( finishedmessage => {
message = "\n It's time to vote! Reply `!ready " + vote + "` in the channel or DM if you are ready to vote. You have 5min to respond"
votermessage = `${finishedmessage}${message}`
receivedMessage.channel.send(votermessage)
console.log ("BEFORE SET TIMEOUT")
})
const mentionUsers = (vote) => new Promise ((resolve, reject) => {
var message_string = ""
var userQuery = "SELECT * FROM vote WHERE format = $1;"
userQueryValues = [vote]
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
queued.forEach(voter =>{
message_string = message_string.concat(' ', "<@"+voter.discordid+">")
})
})
.finally( () =>{
resolve(message_string)
})
.catch((err) => {console.error(`Error building vote message: ${e}`)})
})

mentionUsers(vote)
.then( finishedmessage => {
message = "\n It's time to vote! Reply `!ready " + vote + "` in the channel or DM if you are ready to vote. You have 5min to respond"
votermessage = `${finishedmessage}${message}`
receivedMessage.channel.send(votermessage)
console.log ("BEFORE SET TIMEOUT")
})
Got it, I’ll remove the var’s but userQueryValues is declared in the 4th line? Got it again, thank you, that's updated now too
const mentionUsers = (vote) => new Promise ((resolve, reject) => {
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
message_string = message_string.concat(' ', "<@"+voter.discordid+">")
})
})
.finally( () =>{
//console.log(message_string)
resolve(message_string)
})
.catch((err) => {console.error(`Error building vote message: ${e}`)})
})
const mentionUsers = (vote) => new Promise ((resolve, reject) => {
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
message_string = message_string.concat(' ', "<@"+voter.discordid+">")
})
})
.finally( () =>{
//console.log(message_string)
resolve(message_string)
})
.catch((err) => {console.error(`Error building vote message: ${e}`)})
})
const startReadyCheckSequence = (receivedMessage, vote, client) => {
console.log("entering start ready check loop")
//message = "It's time to vote! The queue will be open for the next **5 minutes**. Reply `!ready " + vote + "` in the channel or DM if you are ready to vote."
let message = "\nIt's time to vote **" + vote.toUpperCase() + "**! DMs have been sent out to the pod!"
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
let votermessage = ""
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach( voter => {
//console.log("%o",voter)
DMtoSend = `Hello **${voter.discordname}**! Your pod for **${vote.toUpperCase()}** is ready!`
console.log(`Sending Message to ${voter.discordname}`)
client.users.send(voter.discordid, DMtoSend)
})
})
.finally( () => {
mentionUsers(vote)
.then( finishedmessage => {
votermessage = `${finishedmessage}${message}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: votermessage})
console.log ("BEFORE SET TIMEOUT")
})
})
const startReadyCheckSequence = (receivedMessage, vote, client) => {
console.log("entering start ready check loop")
//message = "It's time to vote! The queue will be open for the next **5 minutes**. Reply `!ready " + vote + "` in the channel or DM if you are ready to vote."
let message = "\nIt's time to vote **" + vote.toUpperCase() + "**! DMs have been sent out to the pod!"
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
let votermessage = ""
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach( voter => {
//console.log("%o",voter)
DMtoSend = `Hello **${voter.discordname}**! Your pod for **${vote.toUpperCase()}** is ready!`
console.log(`Sending Message to ${voter.discordname}`)
client.users.send(voter.discordid, DMtoSend)
})
})
.finally( () => {
mentionUsers(vote)
.then( finishedmessage => {
votermessage = `${finishedmessage}${message}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: votermessage})
console.log ("BEFORE SET TIMEOUT")
})
})
There's the two updates as per Qjuh's help! The issue remains though, after sending the DMs and message to the vote channel, the bot goes offline with no error. It just hangs. the node process actually doesn't close, I have to CTRL+C to close the process
d.js docs
d.js docs14mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
Draechen
DraechenOP14mo ago
Thank you again. On it.
const mentionUsers = (vote) => new Promise ((resolve, reject) => {
"use strict";
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
message_string = message_string.concat(' ', "<@"+voter.discordid+">")
})
})
.finally( () =>{
//console.log(message_string)
resolve(message_string)
})
.catch((err) => {console.error(`Error building vote message: ${e}`)})
})
const mentionUsers = (vote) => new Promise ((resolve, reject) => {
"use strict";
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach(voter =>{
//console.log("%o",voter)
message_string = message_string.concat(' ', "<@"+voter.discordid+">")
})
})
.finally( () =>{
//console.log(message_string)
resolve(message_string)
})
.catch((err) => {console.error(`Error building vote message: ${e}`)})
})
const startReadyCheckSequence = (receivedMessage, vote, client) => {
"use strict";
console.log("entering start ready check loop")
//message = "It's time to vote! The queue will be open for the next **5 minutes**. Reply `!ready " + vote + "` in the channel or DM if you are ready to vote."
let message = "\nIt's time to vote **" + vote.toUpperCase() + "**! DMs have been sent out to the pod!"
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
let votermessage = ""
let DMtosend = ""
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach( voteer => {
//console.log("%o",voteer)
DMtoSend = `Hello **${voteer.discordname}**! Your pod for **${vote.toUpperCase()}** is ready!`
console.log(`Sending Message to ${voteer.discordname}`)
client.users.send(voter.discordid, DMtoSend)
})
})
.finally( () => {
mentionUsers(vote)
.then( finishedmessage => {
votermessage = `${finishedmessage}${message}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: votermessage})
console.log ("BEFORE SET TIMEOUT")
})
})
}
const startReadyCheckSequence = (receivedMessage, vote, client) => {
"use strict";
console.log("entering start ready check loop")
//message = "It's time to vote! The queue will be open for the next **5 minutes**. Reply `!ready " + vote + "` in the channel or DM if you are ready to vote."
let message = "\nIt's time to vote **" + vote.toUpperCase() + "**! DMs have been sent out to the pod!"
let message_string = ""
const userQuery = "SELECT * FROM vote WHERE format = $1;"
const userQueryValues = [vote]
let votermessage = ""
let DMtosend = ""
dbs.voteQueue(userQuery, userQueryValues)
.then(queued => {
//console.log("%o",queued)
queued.forEach( voteer => {
//console.log("%o",voteer)
DMtoSend = `Hello **${voteer.discordname}**! Your pod for **${vote.toUpperCase()}** is ready!`
console.log(`Sending Message to ${voteer.discordname}`)
client.users.send(voter.discordid, DMtoSend)
})
})
.finally( () => {
mentionUsers(vote)
.then( finishedmessage => {
votermessage = `${finishedmessage}${message}`
client.channels.cache.get(BOT_VOTE_CHANNEL, true)
.send({content: votermessage})
console.log ("BEFORE SET TIMEOUT")
})
})
}
Alright, strict mode on and variables all declared, but the same thing is happening. Another update, the bot goes offline, but comes back after 15-20 minutes of downtime? Here is what the console shows:
[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.2764877814090323; waiting 11405ms [WS => Shard 0] Waiting for identify throttle [WS => Shard 0] Identifying shard id: 0 shard count: 1 intents: 38403 compression: none
That's what happens when it comes back online. There's nothing in the console. No activity at all for that 15 minute window. Sorry, let me get a link with all the code. I've just been trying to step through everything to see where it stops, and it looks like it finishes the message.create event (which is when the last person signals they're ready) and then nothing until this reconnect message after 15-20 minutes BTW thank you so much for your patience and help as I stumble through all this Here's the full file: draebot.js - https://sourceb.in/qfLtkyu6xR voteCommands.js -https://sourceb.in/nEaiLuV0sj db.js - https://sourceb.in/LbBNNRrNXX (as a precursor I haven't strict-moded the other two files, just the votecommands)
================ 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
<here's where the pause occurs>
================ 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
Will do! No change in the output in the console. Same 15ish minute pause before it comes back online. 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. 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. 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. 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? voteStatus is the return from a query to the postgres db. and voteStatus.usersNotReady is an array of usernames .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)
}
})
})
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}`)})
})
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 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}`})
}
}
}
}
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. 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. 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.
Want results from more Discord servers?
Add your server