Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

375
Vistas
How do I logout my Discordbot in JS savely with a command

I built a basic Discord bot which I want to go offline when I type the corresponding command on the Discord server "!logout". I searched for answers, but those who used discord.js weren't responsed...

If I use client.logout() it throws an error and crashs with

TypeError: client.logout is not a function

and it won't even call my error function. Maybe the answer is simple but I can't find it anywhere.

Here's my basic code:

require('dotenv').config()

const Discord = require('discord.js')
const client = new Discord.Client({ 
  intents: ["GUILDS", "GUILD_MESSAGES"],
})

client.on('ready', () => {
    console.log('Bot is ready');
});

client.on("messageCreate", msg => {
  if (msg.content === '!logout'){
    
      client.logout(() => {
        msg.reply('couldn^t go offline')
      })
    }
  
  
})

client.login(process.env.BOT_TOKEN)

Thank you! :)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try using the function <Client>#destroy()

If you want to exit Node.js, you can then use process.exit(0)

Documentation

about 4 years ago · Juan Pablo Isaza Denunciar

0

process.exit(0)

From the docs:

process.exit([exitcode]) Ends the process with the specified code. If omitted, exit uses the 'success' code 0.

To exit with a 'failure' code:

process.exit(1); The shell that executed node should see the exit code as 1.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda