所以我想这样做,如果我这样做:
我试过了:
await message.channel.send("Send your file please..");
const MSG1 = await message.channel.awaitMessages(msg => {
const buffer = fs.readFileSync(`${msg.url}`);
message.channel.send('Read the file! Fetching data...');
message.channel.send(buffer)
})
和
await message.channel.send("Send your file please..");
const MSG1 = await message.channel.awaitMessages(msg => {
fs.readFile(Buffer.from(MSG1.attachments.first()), 'utf8', function(err, data) {
if (err) throw err;
console.log('Read the file! Fetching data...');
console.log(data);
})
})
和
await message.channel.send("Send your file please..");
const MSG1 = await message.channel.awaitMessages(msg => {
fs.readFile(Buffer.from(`${msg.attachments.first().attachment}`), 'utf8', function(err, data) {
if (err) throw err;
console.log('Read the file! Fetching data...');
console.log(data);
})
})
和
await message.channel.send("Send your file please..");
const MSG1 = await message.channel.awaitMessages(msg => {
let buffer = Buffer.from(msg.attachments.first().attachment)
message.channel.send('Read the file! Fetching data...');
message.channel.send(buffer)
})
但这些都不起作用。
答案 0 :(得分:0)
我看到您正在使用TextChannel.awaitMessages(),就好像它具有回调参数一样,但是您传递的函数应该是filter。不用awaitMessages(function)
,而要使用awaitMessages().then(function)
。
话虽如此,我还建议仅在作者相同的情况下使用过滤器并获取附件:
let filter = m => m.author == message.author; //use that message only if the author is the same
message.channel.awaitMessages(filter, {max: 1}).then(msg => {
let file = msg.attachments.first().file;
fs.readFile(file, (err, data) => {
msg.channel.send("Read the file! Fetching data...");
msg.channel.send(data);
});
});
应该可以,如果您有任何问题,请告诉我