So I am making a pause function for a bot where when it is set to true the bot won't respond to any of its trigger words till it is unpaused. I cut out a lot of the code to only the parts relevant to my question so please excuse the format looking a bit weird.
const prefix = "!";
// enabled by default
client.isPaused = false;
client.on("messageCreate", (message) => {
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (message.author.id === client.user.id) {return};
if (command === 'pause') {
if (client.isPaused = true){
message.reply({ content:`The bot is already paused. Use \`${prefix}unpause\` to unpause it.`}) };
if (client.isPaused = false){
message.reply({ content:`The bot is paused. Use \`${prefix}unpause\` to unpause it.`})
set(client.isPaused = true)}; };
if (command === 'unpause') {
if (client.isPaused = false){
message.reply({ content: `The bot is already listening to commands, can't unpause it.`,})};
if (client.isPaused = true) {
message.reply({ content:`The bot is now unpaused.`})
set(client.isPaused = false)}; };
// if bot is paused, exit so the commands below will not get executed
if (client.isPaused = true) {return};
});
Pause works fine and has permanently put the bot in a paused state until I have this figured out. Restarting the bot doesn't get it out of the paused state either, but when I try to use !unpause the console responds with:
C:\Users\thorn\Desktop\HYPEBOT\index.js:96
set(client.isPaused = false)}; };
^
ReferenceError: set is not defined
at module.exports.<anonymous> (C:\Users\thorn\Desktop\HYPEBOT\index.js:96:7)
at module.exports.emit (node:events:513:28)
at MessageCreateAction.handle (C:\Users\thorn\Desktop\HYPEBOT\node_modules\discord.js\src\client\actions\MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (C:\Users\thorn\Desktop\HYPEBOT\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\thorn\Desktop\HYPEBOT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\thorn\Desktop\HYPEBOT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:480:22)
at WebSocketShard.onMessage (C:\Users\thorn\Desktop\HYPEBOT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:320:10)
at WebSocket.onMessage (C:\Users\thorn\Desktop\HYPEBOT\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:513:28)
at Receiver.receiverOnMessage (C:\Users\thorn\Desktop\HYPEBOT\node_modules\ws\lib\websocket.js:1178:20)
Node.js v18.10.0
I am stumped on how to fix this error and any help would be greatly appreciated.