When I’m trying to upload every file to a new discord forum thread, I’m getting the error “TypeError: this.options.files?.map is not a function” I’ve got everything else until there to work myself but I’m not too sure where to start with this error if anyone can help me that will be great the code is below:
client.on('messageCreate', async message => {
// Check if the message author is the bot
if (message.author.bot) return;
// Check if the message contains the !upload command
if (message.content.startsWith('!upload')) {
// Get the directory path from the message content
const dirPath = message.content.split(' ')[1];
thread = "1099921205324173332"
// Check if the directory exists
const fs = require('fs');
if (fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory()) {
// The directory exists, so read all the files in the directory
const fileNames = fs.readdirSync(dirPath).filter(fileName => fileName.endsWith(".csv"));
// Loop through each file and upload it to the channel
for (const fileName of fileNames) {
// const filePath = `${dirPath}/${fileName}`;
// const buffer = fs.readFileSync(filePath);
GuildForumMessageRequired = 'GuildForumMessageRequired'
{
const threadChannel = message.guild.channels.cache.find(channel => channel.name === 'test');
threadChannel.threads.create({
name: fileName.name,
autoArchiveDuration: 60,
type: 'GUILD_PUBLIC_THREAD',
message: {
content: `New thread created with file:` ,//"${fileName.name.replace('/[^a-zA-Z ]/g, ""')}!`,
files:fileName
}
});
}
console.log(`Uploaded ${fileName} to ${message.channel.name}`);
}
}
else
{
// If the directory doesn't exist, send an error message
message.reply('The specified directory does not exist.');
}
console.log(`Created thread: ${thread.name}`);
}
});
What should be happening within this code is that with every new file it puts it in a new discord forum thread with the file name as the title and the message as the file but what I’m getting currently is this error message: