Bot Does Not Respond

My Discrod.JS bot is online but not responding. This is the code-

// require the discord.js module
const Discord = require('discord.js');

// create a new Discord client
const client = new Discord.Client();

// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
	console.log('Ready!');
});

module.exports = function(controller) {
  controller.hears(
    "!appreciates",
    ["direct_mention", "mention"],
    (bot, message) => {
      let response;
      let sender = message.user;
      let recipient = message.mentions.users
        .filter(user => user.bot === false)
        .last();
      let responses = [
        `Hey, ${sender}, I appreciate you!  :heart_eyes:`,
        `Hey, ${sender}, I appreciate your enthusiasm!  :muscle:`,
        `Hey, ${sender}, I appreciate your commands!  :wink:`,
        `Hey, ${sender}, I appreciate your particaption! :grinning:`,
        `Hey, ${sender}, I appreciate all your works! :blush:`,
        `Hey, ${sender}, I appreciate everything you do. :star_struck:`
      ];

      response = responses[Math.floor(Math.random() * responses.length)];

      bot.reply(message, response);
    }
  );
};
client.login('app token');

There is no error in the console. The only message is “Ready!”.

And here is my package.json-

{
  "name": "rbot4discord",
  "version": "2.0.0",
  "engines": {
    "node": "12.x"
  },
  "description": "A simple Discord bot",
  "main": "bot.js",
  "scripts": {
    "start": "node bot.js"
  },
  "author": "R4356th",
  "dependencies": {
    "discord.js": "^12.3.1"
  },
  "devDependencies": {
    "minimist": ">=1.2.2"
  }
}

Has your bot been banned? Do you have a correct token?

1 Like

I made a bot with the same name and almost the same code last month. This one is new. Let me check if it banned.

This is funny. Discord says my bot is online but it is sleeping. :thinking:

It is not sleeping and it has the correct token.

I am now getting this error-

(node:3362) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at WebSocketManager.connect (/rbd/pnpm-volume/731183ff-7638-49e9-924e-544b63889d39/node_modules/.registry.npmjs.org/discord.js/12.3.1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:133:26)
    at Client.login (/rbd/pnpm-volume/731183ff-7638-49e9-924e-544b63889d39/node_modules/.registry.npmjs.org/discord.js/12.3.1/node_modules/discord.js/src/client/Client.js:222:21)
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:54:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:828:11)
    at internal/main/run_main_module.js:17:11
(node:3362) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3362) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Ready!
(node:3495) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at WebSocketManager.connect (/rbd/pnpm-volume/731183ff-7638-49e9-924e-544b63889d39/node_modules/.registry.npmjs.org/discord.js/12.3.1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:133:26)
    at Client.login (/rbd/pnpm-volume/731183ff-7638-49e9-924e-544b63889d39/node_modules/.registry.npmjs.org/discord.js/12.3.1/node_modules/discord.js/src/client/Client.js:222:21)
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:54:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:828:11)
    at internal/main/run_main_module.js:17:11
(node:3495) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3495) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Ready!

This says my token is invalid but I am sure it is not. :frowning:

Could you try resetting it? (can’t hurt)

1 Like

The project is stuck at starting for three minutes now just like before. However, the error is gone now.

I just took a look at the project hours count for that project and it has taken only one project hour!

I found that my bot is logging in to Discord as expected even though Glitch is showing me loading screen. However, it is still not responding to messages. By the way, I just made the project public and you can view it here-

Bump

Bump

Are you still getting the token error?

I am not an expert on Discord bots, so I might be completely wrong, but it does not look like you ever call the function that you export; module.exports = function(controller). In that case everything inside the function will never run.

1 Like

No.