发送文件到不和谐论坛

编程入门 行业动态 更新时间:2024-10-04 23:31:53

发送文件到<a href=https://www.elefans.com/category/jswz/34/1770292.html style=不和谐论坛"/>

发送文件到不和谐论坛

我试图一次将每个文件发送到一个不和谐的论坛,但没有任何效果,这意味着创建一个新的不和谐论坛,然后在论坛的标题中出现 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 论坛,标题是文件名,然后是描述中的文件,但实际输出在此图像中

我修复了回调函数,但我得到的文件未定义

回答如下:

更多推荐

发送文件到不和谐论坛

本文发布于:2024-05-30 10:44:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不和谐   文件   论坛

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!