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! :)
CodePudding user response:
Try using the function <Client>#destroy()
If you want to exit Node.js, you can then use process.exit(0)
CodePudding user response:
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.