Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  138] [ 6]  / answers: 1 / hits: 8566  / 3 Years ago, sun, august 15, 2021, 12:00:00

After upgrading to discord.js v13 and using Array.from(message.attachments.values()) instead of message.attachments.array() to send attachments from a message,


message.client.channels.cache.get("123456789").send({
files: [Array.from(message.attachments.values())],
content: `test`
});

I get an error from the console from the node module:


DesktopBotnode_modulesdiscord.jssrcstructuresMessagePayload.js:223
if (thing.path) {
^

TypeError: Cannot read property 'path' of undefined

The part where the error comes is here:


const findName = thing => {
if (typeof thing === 'string') {
return Util.basename(thing);
}

if (thing.path) {
return Util.basename(thing.path);
}

return 'file.jpg';
};

I'm really confused on what's wrong or how to fix it, any help?


More From » discord.js

 Answers
0

You are creating an array inside of an array, remove the extra square brackets. Array.from() returns a new instance of an Array already.


message.client.channels.cache.get("channel id").send({
files: Array.from(message.attachments.values()),
content: `test`
});

Alternatively you could spread the iterable into an array using the spread operator.


message.client.channels.cache.get("channel id").send({
files: [...message.attachments.values()],
content: `test`
});

[#992] Wednesday, August 4, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
Tue, Jan 28, 20, 00:00, 4 Years ago
;