升级到discord.js v13并使用后Array.from(message.attachments.values())
代替message.attachments.array()
发送消息中的附件,
message.client.channels.cache.get("123456789").send({
files: [Array.from(message.attachments.values())],
content: `test`
});
我从节点模块的控制台收到错误:
Desktop\Bot\node_modules\discord.js\src\structures\MessagePayload.js:223
if (thing.path) {
^
TypeError: Cannot read property 'path' of undefined
出现错误的部分在这里:
const findName = thing => {
if (typeof thing === 'string') {
return Util.basename(thing);
}
if (thing.path) {
return Util.basename(thing.path);
}
return 'file.jpg';
};
我真的很困惑到底出了什么问题或如何解决它,有什么帮助吗?
您正在数组内部创建数组,请删除多余的方括号。Array.from() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from返回一个新实例Array
已经。
message.client.channels.cache.get("channel id").send({
files: Array.from(message.attachments.values()),
content: `test`
});
或者,您可以使用以下方法将可迭代对象扩展到数组中:扩展运算符 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax.
message.client.channels.cache.get("channel id").send({
files: [...message.attachments.values()],
content: `test`
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)