Message from Discord: Unable to access the property 'MessageEmbed' because it is undefined

Attempting to create a simple welcome message embed. Here is my main.js file without the login token:

const Discord = require('discord.js');
const client = new Discord.Client();
const MessageEmbed = new Discord.MessageEmbed();

const prefix = 'm.';
const fs = require('fs');

client.commands = new Discord.Collection();
client.events = new Discord.Collection();

const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
    const event = require(`./events/${file}`);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args));
    } else {
        client.on(event.name, (...args) => event.execute(...args));
    }
}

and here is welcome.js with the exception of defining channelId:

module.exports = {
    name: 'guildMemberAdd', 
    execute(member, Discord) {

        console.log('login');

        const message = `Welcome <@${member.id}> !`;
        const channel = member.guild.channels.cache.get(channelId);

        const joinEmbed = new Discord.MessageEmbed()
            .setTitle(`New member!`)
            .setDescription(message)
            .setColor("#fab9c7");
        
        channel.send({ joinEmbed });
     },
};

The following error message occurred:

        const joinEmbed = new Discord.MessageEmbed()
                                      ^

TypeError: Cannot read property 'MessageEmbed' of undefined
    at Object.execute (C:\Users\Al\Desktop\MaikaBot\events\welcome.js:11:39)
    at Client.<anonymous> (C:\Users\Al\Desktop\MaikaBot\main.js:17:44)
    at Client.emit (events.js:400:28)
    at Object.module.exports [as GUILD_MEMBER_ADD] (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\handlers\GUILD_MEMBER_ADD.js:16:14)
    at WebSocketManager.handlePacket (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\Al\Desktop\MaikaBot\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:400:28)
    at Receiver.receiverOnMessage (C:\Users\Al\Desktop\MaikaBot\node_modules\ws\lib\websocket.js:970:20)

If this seems too basic, apologies as I'm still in the process of learning JavaScript. The module syntax continues to elude me.

Answer №1

The specified Discord is currently not defined within your module. This issue arises due to the fact that only one argument is being passed to the callback function of the guildMemberAdd event, which is a GuildMember.

To resolve this, you can either require discord.js in your module or include Discord as an argument when executing the execute function.

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

Revamping the values attribute of a table embedded in a JSP page post an AJAX invocation

I am encountering an issue with displaying the content of a table. The table's data is retrieved via an AJAX request when clicking on a row in another table on the same page. Here is my code for the JSP page: <table id="previousList" class="table" ...

Is `h` equal to `createVNode` function?

Both h and createVNode are exposed from vue. The documentation on this page seems to imply that they are interchangeable: The h() function is a utility to create VNodes. It could perhaps more accurately be named createVNode(). However, replacing h with ...

Having trouble getting a JS file to work with the Laravel Inertia.js and Vue.js3 template

Just getting started with inertia.js and facing an issue. My CSS styles are being applied, but my JavaScript file isn't functioning as expected. I'm working on an admin dashboard using Laravel 9 and vue.js-3 with a custom HTML template. Interes ...

Ways to retrieve all elements based on their class names?

What is the equivalent of using $('.class') in JQuery to get all elements by class name with pure JavaScript? ...

FullCalendar displaying inaccurate dates and times

In my ASP.NET MVC application, a full calendar element is displayed as shown below: Here is the JSON data returned by the server through an ajax call for the month of January 2016: [{"id":17,"title":"39/2015 - Site meeting test 3","start":"\/Date(14 ...

Changing the value in a URL String using JavaScript

I am in possession of a String that contains a URL resembling the following: var url ="http://ispeakphone.com/checkout/cart/add/uenc/aHR0cDovL2lzcGVha3Bob25lLmNvbS9zYW1zdW5nL3NhbXN1bmctZ2FsYXh5LXMvZ2FsYXh5LXM5LXBsdXMuaHRtbA,,/product/619/form_key/foxmD7jg ...

Error in typing on a prismic application utilizing a ContentRelationshipField

I am facing a type error in my Prismic Next.js application that I am struggling to resolve. While the app functions properly, I keep encountering type errors like the following: The property 'data' does not exist on the type 'ContentRelati ...

Using jQuery to decrease the size of a div element containing an image

Hello everyone! I have an image inside a div and I am currently moving it down at a specific time using a delay. My question is, how can I make the image shrink as it moves down the screen until it eventually disappears completely at a set location? Curre ...

The default expansion behavior of Google Material's ExpansionPanel for ReactJS is not working as expected

Currently, I am in the process of developing a ReactJS application that utilizes Google's Material-UI. Within this project, there is a child class that gets displayed within a Grid once a search has been submitted. Depending on the type of search con ...

The feature to prevent multiple selections in JSTree is not functioning as expected

Incorporating JSTree into my application involves the code below. this.CreateTreeView = function () { $('#jstree_demo_div').jstree({ 'core': { 'multiple': false, 'data': [ ...

Issue with handling promise rejection of type error in node.js

Whenever I try running node server.js in Node.js, an error message pops up saying 'Cannot read property 'length' of undefined'. Despite installing all the necessary libraries (such as request) and browsing through various related posts ...

What is the best way to display multiple sets of table data on a single page without any connections between them?

Is there a way to combine data from two tables (dept_db, role_db) and display it on my createUsers page? I am looking for a solution where the page only needs to be rendered once to retain the previous query results. Thank you. exports.createUsers = func ...

The entirety of the text has been mirrored to the right in React Native code

Is there a way to align this text on both the left and right sides, along with styling the button and text input elements to be more colorful and have bigger fonts? Below is an example of the desired outcome: This is what I have attempted so far: <Vie ...

Guidelines on launching an ionic 4 modal using routes

How can I open a modal using routes? I attempted the following approach, but it did not work as expected: ngOnInit() { this.launchModal(); } async launchModal() { const modal = await this.modalController.create({ component: AuthPasswordR ...

"Unable to get elements by tag name using the getElementsByTagName method in

function updateLayout() { var para = document.getElementsByTagName("p"); para[0].style.fontSize = 25; para[1].style.color = "red"; } <p>Text in paragraph 1</p> <p>Text in paragraph 2</p> <p>Text in paragraph 3</p& ...

The export of 'alpha' is not available in the '@mui/system' module

Help! I am encountering an error related to the @mui/material library. I have already looked into the package.json file of mui/system and it seems that 'alpha' is exported in it. ./node_modules/@mui/material/styles/index.js Attempted import erro ...

What is the best way to manage the back button using jQuery?

I'm currently facing a challenge when it comes to managing the Browser's History. While plugins like History.js can be helpful for smaller tasks, I find myself struggling with more complex scenarios. Let me provide an example: Imagine I have a m ...

When attempting to install React Native on a Mac using the "npx react-native init MyTestApp" command, the

PROBLEM I am encountering difficulties while attempting to install and execute the react native todo command - npx react-native init MyTestApp on my MacBook Pro. The specific challenges I am facing are: The detailed github issue can be found here: here ...

Is there a way for me to connect to my Firebase Realtime Database using my Firebase Cloud Function?

My current challenge involves retrieving the list of users in my database when a specific field is updated. I aim to modify the scores of players based on the structure outlined below: The Realtime Database Schema: { "users": { &quo ...

Best practices for effectively managing a sizable dataset in Vue.js

My task at hand is to create a visualization dashboard that can operate solely in the browser, utilizing Vue.js, D3, and JavaScript. The dataset I am working with is stored in a .json file that is 48 MB in size. However, upon parsing the file using d3.json ...