I am attempting to create a hibernation feature for my Discord bot that allows it to appear online without responding to messages. Below is the code I’ve attempted:
let settings = JSON.parse(fs.readFileSync('config.json')); // Checking if hibernate mode is activated
if (settings.hibernate === true) {
client.user.setPresence({ status: 'idle' });
client.user.setActivity('Bot is in hibernation');
console.log('Currently hibernating');
return;
} else {
client.user.setPresence({ status: 'online' });
client.user.setActivity('');
console.log('No longer in hibernation');
}
I’ve placed this code outside my message event listener, inside bot.once('ready', () => {}, but I encounter an error saying “cannot read property ‘setPresence’ of null.” My objective is to ensure that during hibernation, the bot goes idle and shows a status message indicating it’s hibernating, while also avoiding message handling. Any suggestions on how to achieve this?