Having some trouble with my Discord bot's userinfo code. I've got everything set up and running smoothly, but it seems like the Joined Server field is showing up as undefined when it loads

I am currently using node along with visual studio code. The script is running smoothly and the text is being embedded just below the field title. However, instead of displaying the server join date, it is showing 'undefined'.

switch(args[0]){
        case 'userinfo':         
            let usera = message.mentions.users.first()
            if(!usera) return message.channel.send("Must specify user")
            const joinDiscord = moment(user.createdAt).format('llll')
            
            let embed = new Discord.MessageEmbed()
                .setAuthor(usera.tag, usera.avatarURL)
                .addField("ID", usera.id, true)
                .addField("Username", usera.username, true)
                .addField("Status", usera.presence.status, true)
                .addField("Joined Server",usera.joinedAt, true)//its this part
                .addField("Created", usera.createdAt, true)
                .addField("Bot", usera.bot, true)
                .setTimestamp()
                .setColor(0x0f7fa6)
                .setThumbnail(usera.displayAvatarURL())
                message.channel.send({embed});
                        
        }
    });
    

Answer №1

joinedAt is a variable that pertains to the guildMember object type, but you currently have a user object. To obtain the member object from the user object, follow these steps:

switch(args[0]){
case 'userinfo':         
     let usera = message.mentions.users.first()
     if(!usera) return message.channel.send("Must specify user")
     const joinDiscord = moment(user.createdAt).format('llll')

          let embed = new Discord.MessageEmbed()
          .setAuthor(usera.tag, usera.avatarURL)
          .addField("ID", usera.id, true)
          .addField("Username", usera.username, true)
          .addField("Status", usera.presence.status, true)
          .addField("Joined Server",message.guild.members.cache.get(usera.id).joinedAt, true)//got the guild member from the users id
          .addField("Created", usera.createdAt, true)
          .addField("Bot", usera.bot, true)
          .setTimestamp()
          .setColor(0x0f7fa6)
          .setThumbnail(usera.displayAvatarURL())
     message.channel.send({embed});
                        
}
});

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

Obtaining status codes from URLs can be achieved by leveraging various methods

Hey there, I'm just starting out with javascript and AngularJS. Here's a function I wrote to retrieve JSON data from the server: function getProducts() { return $http.get(urlProducts).then( //Success function(resp ...

What is the abbreviated term for personalized elements in React Native development?

After discovering that custom components can be created like this: const CustomComp=()=>{ console.log('Created custom comp'); return(<View></View>); } export default function App(){ return(<View style={{flex:1}}> &l ...

Encountering an error while trying to load a CSS file in a React project using webpack due

I'm currently working on a React project that utilizes styled components, and I've been attempting to integrate a CSS file as part of the react-image-gallery package. Following the instructions provided, I included the css-loader and style-loade ...

Incorporate the results from ajax into a function callback within a plugin (jQuery)

How can I access the output of an AJAX call within a callback function in my plugin? My plugin is designed for a contact form that sends data via AJAX, and I need to be able to view the output in a log or alert. The plugin already includes a callback funct ...

How can I specify the localStorage key to use for the login process?

Hello! I've been exploring ways to store objects in localStorage and have successfully created a registration user system using JSON and localStorage. This system stores the user's id, username, and password without any issues of data resetting o ...

JavaScript library unsuccessful in transferring data to PHP script

I am facing an issue while trying to transfer variables from javascript to a php file for execution. The problem is that the php file is not being called or executed, even though I have confirmed that it works properly when tested individually. $(function ...

Utilizing Node.js and Express.js to Parse HTML Form Inputs

Having trouble extracting input from an HTML form and utilizing it in Node.js. Here is the HTML form being used: <form action="/myform" method="POST"> <input type="text" name="mytext" required / ...

Is there a way to access configurations from a module import in NestJS?

If my module is defined as shown below: @Module({ imports: [ PassportModule.register({ defaultStrategy: 'jwt' }), JwtModule.register({ // Use ConfigService here secretOrPrivateKey: 'secretKey', signOptions: ...

The simultaneous triggering of two button events is not occurring in a TypeScript environment

I have a situation where I have 2 buttons positioned next to each other: Current year PR signature and Prior year PR signature Upon clicking on either the Current year or Prior year PR signature button for the first time, it successfully retrieves and dis ...

"Implementing a comment system using Node.js and MySQL: A comprehensive guide

Hey there! I have some data that I want to use to create a hierarchical data example. { id_commentForum: 1, id_user: 1, id_thread: 1, comment: 'This is the First Comment', parent: 0, created_at: Wed Jun 22 2016 13:36:38 G ...

Attempting to integrate a chatroom name entered by the user using a combination of Ajax and Python

Despite reading numerous textbooks on computer science, I have been struggling with sending ajax form data to Python and checking it in a dictionary before parsing it into a JSON object. The concept of dictionaries with key-value pairs is clear; however, a ...

Drag-and-drop functionality in Angular JavaScript Tree View for rearranging nodes and inserting new nodes

Exploring the world of JavaScript Tree Views and Angular as a beginner. After scouring the internet for information, I'm struggling to find a solution to my specific query. Looking for a tree-view component that seamlessly integrates with Angular, c ...

Accessing QML Functions from JavaScript

Currently, I am faced with a challenge in my app development using Qt. I need to trigger a QML function from JavaScript when a specific event is triggered from my HTML page. I attempted the following method: app.html <html> <head><title& ...

JavaScript | Calculating total and separate scores by moving one div onto another div

I have a fun project in progress involving HTML and Javascript. It's a virtual zoo where you can drag and drop different animals into their designated cages. As you move the animals, the total count of animals in the zoo updates automatically with the ...

Can a href from a "<Link>" component be passed through a Higher Order Component (HOC) into an "<a>" tag?

I am currently facing a situation with the main component where I have the following code: <Link href={'test'}> <PrimaryAnchor>Welcome</PrimaryAnchor> </Link> Within the PrimaryAnchor component, the code looks like ...

"Enable real-time editing with inline save/submit feature in

I'm struggling to figure out how to extract the modified content from a CKEditor instance and send it to a URL. I've been referencing something like this: but I can't seem to determine how to save the changes. Is there a way to post the up ...

Tips for configuring the datetimepicker to display time in 15-minute increments

This is a snippet of my custom binding code for a datepicker: ko.bindingHandlers.datepicker1 = { init: function(element, valueAccessor, allBindingsAccessor) { $(function() { $(element).parent().datetimepicker({ pickDate: false, pickSeconds: false ...

Using JQuery for manipulating server controls

I've been working on a jQuery function that interacts with HTML controls $(document).ready(function(){ $('#mydropdown').change(function(){ $selected_value=$('#mydropdown option:selected').text(); $( ...

Inquirer doesn't waste time lingering for user input following a prompt

After initiating the prompt, I'm encountering an issue where inquirer doesn't pause for user input and instead immediately advances to the next command line. Below is the code I'm using: import inquirer from 'inquirer'; var link; ...

Using VueJS to showcase user input in a dynamic list and a pop-up modal

I am attempting to achieve the following: Use a v-for loop to display form input (name, position, company) as an unordered list, showing only the name input and a button for each person When a button is clicked, a modal will appear displaying all the data ...