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:
Desktop\Bot\node_modules\discord.js\src\structures\MessagePayload.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?
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`
});