Encountering a problem while trying to pin a message on Discord

Whenever a message is pinned in discord, it causes the bot to crash with the following error (although it can recover with forever but that's beside the point). The pinned message can be of any type (regular or embed).

    if (!value) throw new RangeError('EMBED_FIELD_VALUE');
                      ^

RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty.
    at Function.normalizeField (..........................................\node_modules\discord.js\src\structures\MessageEmbed.js:432:23)
    at ..........................................\node_modules\discord.js\src\structures\MessageEmbed.js:452:14
    at Array.map (<anonymous>)
    at Function.normalizeFields (..........................................\node_modules\discord.js\src\structures\MessageEmbed.js:451:8)
    at MessageEmbed.addFields (..........................................\node_modules\discord.js\src\structures\MessageEmbed.js:266:42)
    at Client.<anonymous> (..........................................\index.js:323:10)
    at Client.emit (node:events:378:20)
    at MessageCreateAction.handle (..........................................\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (..........................................\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (..........................................\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) {
  [Symbol(code)]: 'EMBED_FIELD_VALUE'

Does anyone have an idea why this happens?

Code starting from line 318 to 336 is requested.

const logs = bot.channels.cache.find(channel => channel.name === 'logs');
    const notifyAdminEmbed = new Discord.MessageEmbed()
        .setColor('#ff6600')
        .setTitle('Keyword Used in Message')
        .setDescription('@here, A member mentioned a keyword you wished to be notified about. Please investigate immediately.')
        .addFields({
            name: 'Message Author',
            value: `<@` + message.author.id + `>`,
            inline: true
        }, {
            name: 'Channel',
            value: `<#` + message.channel.id + `>`,
            inline: true
        }, {
            name: 'Message',
            value: message.content,
            inline: false
        })
        .setTimestamp()

Answer №1

My intuition tells me that the message.content is either undefined or missing (or even an empty string). You might want to consider logging it to verify.

This is just a speculation, as everything else appears to be functioning correctly.

Answer №2

I have identified the root cause of the issue and made the necessary code changes to resolve it. By adding a space before and after the message.content, I was able to eliminate the error that was being thrown.

const logs = bot.channels.cache.find(channel => channel.name === 'logs');
    const notifyAdminEmbed = new Discord.MessageEmbed()
        .setColor('#ff6600')
        .setTitle('Keyword Used in Message')
        .setDescription('@here, A member mentioned a keyword you wished to be notified about. Please investigate immediately.')
        .addFields({
            name: 'Message Author',
            value: `<@` + message.author.id + `>`,
            inline: true
        }, {
            name: 'Channel',
            value: `<#` + message.channel.id + `>`,
            inline: true
        }, {
            name: 'Message',
            value: ' ' + message.content + ' '
            inline: false
        })
        .setTimestamp()

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

Is there a method to implement colorPicker in an Angular WYSIWYG directive without utilizing jQuery?

After removing the jQuery reference, the color picker is no longer functioning in the WYSIWYG directive. In my project, I am avoiding the use of jQuery, so is there a way to achieve this without using jQuery? Alternatively, are there any other editors av ...

Influence the behavior of surrounding elements as we move our cursor over them

I want to create an effect where I have two images, with the first one hidden initially. When we hover over the second image, the first image should become visible. Here are the codes and class names related to the images: <div class="entrycontent"&g ...

Is it possible for my code in ReactJS to utilize refs due to the presence of backing instances?

When working with ReactJS components, I often piece together JSX elements to create my code. For example, take a look at the snippet below. I recently came across this page https://facebook.github.io/react/docs/more-about-refs.html which mentions that "Re ...

Searching for a particular Prettier setting

Seeking a Nicer alternative. I am exploring if there is a way to format code like this without moving the first attribute to a new line: <div class="test-class" [test-binding]="true" (test-binging)="test()" ...

Utilize the href attribute on an image, whether it be through a class

I work as a designer and I'm looking to extract the same href link from class="kt-testimonial-title", either in id="slick-slide10", or in class="kt-testimonial-item-wrap kt-testimonial-item-0", or in class="kt-testimonial-image". Can this be achieved ...

Exploring the use of Vue 3 Composition API, managing Props, and implementing v-if rendering even with a

I'm encountering an issue that I need some help with. In my setup, I have a child component that passes an "active" prop which can be set to either true or false. The intention is for a certain part of the component to show if it's passed as true ...

Save array data to a file in Node.js once it finishes looping

I've been struggling to find a solution to my issue despite looking at examples from other questions. I have created a basic web scraper in nodejs that stores data in an array and now I need help writing this data to a file. I'm having difficulty ...

What alternative can be used for jquery isotope when JavaScript is not enabled?

Is there a backup plan for jQuery isotope if JavaScript isn't working? For instance, if I'm using the fitColumns feature, is there an alternative layout style available in case JavaScript is disabled, similar to what is seen on the new Myspace? ...

JavaScript code snippet to remove a specific element from an array and store it in an object

I am looking to convert an array into an object, where each item in the array is separated into categories as shown below. let a=['monkey: animal','John:human', 'Rob:human', 'donkey:animal'] I expect the output to b ...

The addEventListener method fails to respond to changes in input

Can someone assist me with this issue? I am facing a problem where the input.addeventlistener is not detecting files on change. My setup involves using Vue with Rails. I am looking to trigger the event listener in the mount hook of a Vue component. mo ...

Error message from Angular development server: Channel is reporting an error in handling the response. The UNK/SW_UNREACHABLE options

After recently installing a new Angular app, I encountered an issue while running 'ng serve'. The application initially loads without any problems, but after a few seconds, I started seeing a strange error in the console. Channel: Error in handle ...

The method by which AngularJS identifies the appropriate property within a return value

In Angular, watchers are utilized to identify property changes and trigger a listener function. An example of a watcher declaration is shown below: $scope.food = "chicken"; scope.$watch( function() { return food; }, function(newValue, oldValue) { ...

What is the best way to design a new class that will serve as the parent class for both of my existing classes, allowing them

I am facing a challenge with my programming classes. I have two classes, "Player" and "Enemy", each with similar methods and properties. I want them to inherit from a parent class that I'll create called "Game Object". How can I approach creating thi ...

Is it possible to serialize the entirety of a website's Javascript state, including Closure/Hidden scopes?

My goal is to capture a "snapshot" of a webpage while maintaining its interactive functionality, allowing all Javascript states to be saved and restored. An example scenario where this would be beneficial is when a webpage contains script that utilizes glo ...

Solving the checkbox toggle challenge with recursive functions | Recursive checkbox challenge

I'm currently working on creating a checkbox tree with the following data structure for items const checkboxes = [{ field: 'ARTICLE', id: 41, name: 'Article', parentId: null, checked: false, children: [ ...

How to display currency input in Angular 2

Is there a way to dynamically format input as USD currency while typing? The input should have 2 decimal places and populate from right to left. For example, if I type 54.60 it should display as $0.05 -> $0.54 -> $5.46 -> $54.60. I found this PLUN ...

Refreshing the page in Next.js causes issues with the CSS classNames

I am currently in the process of migrating a React SPA to Next.js, and I am relatively new to this framework. The issue I am encountering is that when I initially load the Home page, everything appears as expected. However, if I refresh the page, incorrect ...

Trouble with serving CSS files using Express static directory

In my app.js file, I have the following code: app.use(express.static(path.join(__dirname, '../public'))); This code snippet is from my main layout page: <link rel="stylesheet" href="/css/styles.css"> Despite trying various combinations, ...

Is there a way to create triangles on all four corners of an image using canvas in JavaScript?

In my code, I am currently working on drawing rectangles on the corners of an image using JavaScript. To achieve this, I first extract the image data from a canvas element. // Get image data let imgData = ctx.getImageData(0, 0, canvas.width, canvas.height) ...

Nightwatch.js feature not functioning properly in a 'closing' manner

I'm facing an issue where I need to execute a function at the beginning of my test before proceeding with the rest of the test steps. Here is the custom command I am using, named internalAdviceLinksHtml: const solr = require('solr-client') ...