Discord bot remains silent and unresponsive

After setting up node.js, my bot is active but it's not responding. Here is the code snippet:

const express = require("express");
const app = express();

app.listen(3000, () => {
  console.log("Project is running!");
})

app.get("/", (req, res) => {
  res.send("Hello world!")
})

const Discord = require("discord.js");
const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]});

client.on("messageCreate", message => {
  if(message.content.toLowerCase() === "ping") {
    message.channel.send("pong");
  }
})

client.login(process.env.token);

I'm stuck and don't know how to fix this issue. Any help would be greatly appreciated.

Answer №1

To access the messageCreate event content, ensure to include the MESSAGE_CONTENT intent in your code:

const express = require("express");
const app = express();

app.listen(3000, () => {
  console.log("Project is running!");
})

app.get("/", (req, res) => {
  res.send("Hello world!")
})

const Discord = require("discord.js");
const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "MESSAGE_CONTENT"]});

client.on("messageCreate", message => {
  if(message.content.toLowerCase() === "ping") {
    message.channel.send("pong");
  }
})

client.login(process.env.token);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Revealing an Angular directive's functionality to a different module

Imagine having a module with a directive structured as follows (this is a rough, untested implementation) There are 3 fundamental requirements that need to be fulfilled: Set up configuration for the element display Add event listeners accessible by the b ...

The malfunctioning of dynamic className styling in React applications

Can someone assist me with an issue I'm having while coding along to a tutorial video? The dynamic styling of className isn't working as expected. I noticed that it works fine on regular CSS, but when using styled-components, I am not getting the ...

Tips on changing the included content of a personalized directive?

Currently utilizing angular 1.x and I've crafted a personalized directive named slider as displayed in the code below. I am attempting to integrate the content of the slider directive using transclude so that I can modify it within the transclude fun ...

AG Grid - revert to default sorting if no columns are currently sorted

When my ag-grid is initialized, it sorts the data by a default column indicated by this.options.defaultSortColumn. If a user then sorts by another column and removes the sort (by clicking on the header three times), I want to revert back to the default sor ...

Distinguishing between native and custom error objects: a comprehensive guide

When working with errors in my node app, I find it challenging to handle both custom and native errors seamlessly. Errors are not just ordinary JavaScript objects, which adds complexity to error handling. To manage custom errors, I am experimenting with t ...

Can an event be passed from one Vue.js component to another without relying on a global EventBus?

I have two independent components that are not directly related to each other. However, I want them to be able to communicate so that when an event is triggered in one component, the other component can respond accordingly. For example, let's conside ...

utilizing JavaScript to play an audio file in .mp3 format on my timer

Hi everyone, I'm a complete beginner in JavaScript. Recently, I've been working on coding a timer that resets its countdown whenever there is mouse movement or a key on the keyboard is pressed. I've managed to get the timer functionality wor ...

Dealing with Errors in Angular Protractor

As a newcomer to using Protractor for automating AngularJS applications, I am encountering difficulties in selecting an element from a list due to issues with error handling caused by promises. In the given code snippet, when providing an invalid category ...

Combining 2 BehaviorSubjects using ForkJoin

I am facing an issue while trying to use forkJoin with two behavior subject streams in Angular. I expected it to return the values of the two subjects, but it is not working as intended. Is there a way to make this work? The subscriptions are not being tr ...

Troubleshooting an Issue with MediaStreamRecorder in TypeScript: Dealing with

I've been working on an audio recorder that utilizes the user's PC microphone, and everything seems to be functioning correctly. However, I've encountered an error when attempting to record the audio: audioHandler.ts:45 Uncaught TypeError ...

Using Jquery to monitor input field modifications following a background ajax refresh

I am facing a challenge with my two JQuery functions. The first function executes an ajax load based on the user's selection from a drop-down menu, and then updates an input field according to the data returned. This function is working correctly. // ...

Manipulate database variables using Javascript

As a beginner in JavaScript, I am seeking assistance with some tasks. I have to save a simple number as a JavaScript variable into a database and display the current value on two websites (with PHP used to retrieve it on the second site). This is my curre ...

An error is being thrown by SetState when included within componentDidmount

I am currently learning React JS and have started working on a small application using it. I'm encountering an issue with the SetState method inside the componentDidMount lifecycle method. The scenario is that I have a parent/home component, which ca ...

How can I toggle specific v-if divs within a v-for loop in Vue.js?

I would like to implement a feature where each post in a loop has a dropdown menu that can be shown/hidden when clicked: <div v-for="(post, index) in posts" :key="index" > <div v-on:click.prevent="toggleDropDown(post)">Show/hide menu & ...

Issue with Angular $compile directive failing to update DOM element

I'm currently working on a project that involves integrating AngularJS and D3 to create an application where users can draw, drag, and resize shapes. I've been trying to use angular binding to update the attributes and avoid manual DOM updates, b ...

Set up a Google Map that is added dynamically

I have developed a form with a Google Map that utilizes 'places autocomplete'. I also added a button on the same page to add another location, which creates another map-canvas div. However, when attempting to initialize another instance of the ma ...

What is the best way to create an Office Script autofill feature that automatically fills to the last row in Excel?

Having trouble setting up an Excel script to autofill a column only down to the final row of data, without extending further. Each table I use this script on has a different number of rows, so hardcoding the row range is not helpful. Is there a way to make ...

Arranging in descending order after computing percentage within a v-for loop

Using Vue.js to calculate percentages, consider the following code snippet: <tr> <span v-for="(item, index) in data.values" :key="index" > {{ item.name }} {{ getPercentage(item.nr) }} </span> </tr& ...

Navigate through a webpage using anchor links without the hash symbol in the URL

My goal is to smoothly navigate through a page using the anchor tag feature. My current method involves: <a href="#div1">Link1</a> <div id='div1'>link1 points me!!</div> Whenever I click on Link1, the page effectively ...

Exploring the Haversine Formula and Geolocation Integration in AngularJS

I am currently developing an application that will organize locations based on either name or distance from the user. Everything is functioning properly except for retrieving the distance. I believe I should be able to obtain the user's coordinates th ...