How to rename a channel when bot goes offline?

Here is what I did:
function updateChannelName(newChannelName) {
const canal = client.channels.cache.get('1295783100709732352')
if (canal) {
try{
canal.setName(newChannelName)
.then(newChannel => console.log(`Channel's new name is ${newChannel.name}`))
.catch(console.error);
return newChannelName
}catch(e){
console.error(e)
return 1
}
}
return 1
}

process.on('SIGINT', async () => {
console.log('exit')
try{
await updateChannelName('❌┃Servidor Offline');
} catch(e){
console.error(e)
}finally{
process.exit(0);
}
});

function updateChannelName(newChannelName) {
const canal = client.channels.cache.get('1295783100709732352')
if (canal) {
try{
canal.setName(newChannelName)
.then(newChannel => console.log(`Channel's new name is ${newChannel.name}`))
.catch(console.error);
return newChannelName
}catch(e){
console.error(e)
return 1
}
}
return 1
}

process.on('SIGINT', async () => {
console.log('exit')
try{
await updateChannelName('❌┃Servidor Offline');
} catch(e){
console.error(e)
}finally{
process.exit(0);
}
});

I can see the 'exit' console log, but the channel isn't renamed. Any help is appreciated. npm: 22.9.0 DJS: 14.16.3
3 Replies
d.js toolkit
d.js toolkit2mo 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 OP
treble/luna
treble/luna2mo ago
well if your bot crashes it wont be able to do stuff
ChilledGaming
ChilledGamingOP2mo ago
maybe I wasn't clear, I mean when i ctrl + c the bot, or (eventually, when I set it up), the systemd service gets stopped ok, is there any way to fix that? Can I make the event listener somehow await the function? (Ive been trying a lot of revisions, but nothing is working, maybe I should make that through another method or shomething? ) Ok, marking as solved.
Want results from more Discord servers?
Add your server