'Discord JS: Shutdown bot via slash command
I have the following command.
const { SlashCommandBuilder } = require("@discordjs/builders")
module.exports ={
data: new SlashCommandBuilder()
.setName("shutdown")
.setDescription("Shutdown the bot"),
async execute(interaction) {
interaction.reply("Shutting down").then(() => {
client.destroy();
})
}
}
The command should shutdown the bot. The only thing it is doing at the moment is crashing the bot because ReferenceError: client is not defined.
I appreciate any help
Solution 1:[1]
Try
process.exit()
Or
const { SlashCommandBuilder } = require("@discordjs/builders")
module.exports ={
data: new SlashCommandBuilder()
.setName("shutdown")
.setDescription("Shutdown the bot"),
async execute(interaction) {
interaction.reply("Shutting down").then(() => {
interaction.client.destroy();
})
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nirav Joshi |
