不和谐论坛"/>
发送文件到不和谐论坛
我试图一次将每个文件发送到一个不和谐的论坛,但没有任何效果,这意味着创建一个新的不和谐论坛,然后在论坛的标题中出现 csv 文件名,然后在描述中放入文件它自己。但出于测试目的,我一直在尝试查看是否可以让机器人一次只发送一个文件,但我一直收到类型错误,我不知道如何修复它,代码如下:
const { Client, GatewayIntentBits, MessageAttachment } = require('discord.js');
const fs = require('fs');
const path = require('path');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
]
})
const channelId = '1234567890'; // Replace with your channel ID
const directoryPath = './aar/'; // Replace with your directory path
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async (message) => {
if (message.content === '!send-files') {
const files = await readDirectory(directoryPath);
if (files.length === 0) {
message.channel.send('No files found!');
return;
}
for (const file of files) {
const attachment = new MessageAttachment(file.path);
await message.channel.send({ files: [attachment] });
}
}
});
async function readDirectory(directoryPath) {
files(cb)({
files: fs.readdir(directoryPath),
return(directoryPath){
const csvFiles = files.filter((file) => file.endsWith('.csv'));
const fileData = csvFiles.map((file) => {
const filePath = `${directoryPath}/${file}`;
return { name: file, path: filePath };
})
},
return :fileData,
})
}
client.login('token goes here');
bot 应该是新的 discord 论坛,标题是文件名,然后是描述中的文件,但实际输出在此图像中
我修复了回调函数,但我得到的文件未定义
回答如下:更多推荐
发送文件到不和谐论坛
发布评论