Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord.js Array coming as undefined

The command is taking in an image and some text with it in channel-1 and posting the same image and text in channel-2.
The image gets posted but the text comes out as undefined but when i print out the value in the console it is not empty.

Input in channel -1
input in channel 1

Output in channel 2
Output in channel 2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Code

    if(!args.length){
        return message.channel.send(`${message.author} There was no input,Command: ${message} ,your input: ${args}`);
    }
    var str= args.toString();
    const values=str.split(' ');
    client.channels.cache.get("channel-id").send({
        files:Array.from(message.attachments.values()),
        content:`${values[1]}`
    });
    console.log(values);
    client.channels.cache.get("channel-id").send(`here it is --- ${values[1]}`);
} 

Console-

Ready
[ 'hello,world' ] 

>Solution :

I think the problem is with your implementation. You are accessing values[1] whereas in the console.log() it appears the values array has only one element i.e at values[0]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading