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! 🙂