1

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.

Honey Coco
  • 11
  • 2
  • `if (client.isPaused = false){` should be `if (client.isPaused === false){` Almost every `if` in your code is wrong – Konrad Oct 23 '22 at 17:28
  • Tip: `=` and `==` are **extraordinarily different**. Develop an eye for this. These should jump out at you. While learning JavaScript, or other languages that use both types of operator, it may be confusing at first, they do seem so similar, but this is absolutely imperative to get a handle on. – tadman Oct 23 '22 at 17:29
  • `set(client.isPaused = false)}` - this doesn't make sense unless you are trying to golf the code – Konrad Oct 23 '22 at 17:30
  • 1
    Tip: Instead of testing both `x == true` and `x == false`, which is the only other possibility, embrace `else`. Even better, if it's a boolean, omit the `==` part, and do just `if (x)` or `if (!x)`. – tadman Oct 23 '22 at 17:31
  • 2
    `set` isn't a thing in the previous if as well, but you had `if (client.isPaused = true)` which made it skip other conditions – Konrad Oct 23 '22 at 17:31
  • It looks like [one of my answers](https://stackoverflow.com/questions/68419404/disable-the-bot-with-a-command-in-discord-js/68419591#68419591). Why don't you use the if statements like I did? – Zsolt Meszaros Oct 23 '22 at 20:47

0 Answers0