Ben
Ben
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Ben on 2/16/2023 in #djs-questions
Bot stays offline/unresponsive after reconnect
5 replies
DIAdiscord.js - Imagine an app
Created by Ben on 2/16/2023 in #djs-questions
Bot stays offline/unresponsive after reconnect
The actual problem (i think) occurs at 6:09am, when client.on('debug',...) logs [RECONNECT] Discord asked us to reconnect. Logs for this are shown in the 4th screenshot. This (according to my still alive! log) works, however the bot is not logging any heartbeats after this point and also stays offline/unresponsive. Oddly enough, the still alive! log can only be printed, if my "ping" (testing if fetching a hardcoded guild preview is successful) works. This means the bot still has API access internally, however is staying offline for reasons unknown to me. This only gets "fixed", after i manually restart the bot. Any help would be really appreciated. part 3
5 replies
DIAdiscord.js - Imagine an app
Created by Ben on 2/16/2023 in #djs-questions
Bot stays offline/unresponsive after reconnect
Code mentioned above This still gets triggered as still alive!, even after bot no longer sends heartbeats
function checkAliveAndRestart() {
client.fetchGuildPreview(<guild-id>).catch((error) => {
// Set interval to keep checking every 5 seconds
checkAliveInterval = 5000;

// Logging
console.log('level=error msg="bot disconnected!" error="' + stringify(error) + '"');
console.log('level=info msg="attempting to reconnect..."');

// Attempt new login, log depending on success
client.login(process.env['TOKEN']).catch((err) => {
console.log('level=error msg="failed to reconnect!" error="' + stringify(err) + '"');
}).then(() => {
console.log('level=info msg="successfully reconnected!"');
});
}).then(() => {
// Logging
console.log('level=debug msg="still alive!" localTime="' + new Date().toLocaleString() + '"');
// If bot is alive, reset check time back to 30 seconds
checkAliveInterval = 30 * 1000;
});
}
function checkAliveAndRestart() {
client.fetchGuildPreview(<guild-id>).catch((error) => {
// Set interval to keep checking every 5 seconds
checkAliveInterval = 5000;

// Logging
console.log('level=error msg="bot disconnected!" error="' + stringify(error) + '"');
console.log('level=info msg="attempting to reconnect..."');

// Attempt new login, log depending on success
client.login(process.env['TOKEN']).catch((err) => {
console.log('level=error msg="failed to reconnect!" error="' + stringify(err) + '"');
}).then(() => {
console.log('level=info msg="successfully reconnected!"');
});
}).then(() => {
// Logging
console.log('level=debug msg="still alive!" localTime="' + new Date().toLocaleString() + '"');
// If bot is alive, reset check time back to 30 seconds
checkAliveInterval = 30 * 1000;
});
}
part 2
5 replies
DIAdiscord.js - Imagine an app
Created by Ben on 2/13/2023 in #djs-questions
Can't edit a message in DM sent by bot
solved it by adding partials: [Partials.Channel] to the client constructor (
const client = new Client({partials: [Partials.Channel]})
const client = new Client({partials: [Partials.Channel]})
)
4 replies