Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

374
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda