最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

发送文件到不和谐论坛

网站源码admin109浏览0评论

发送文件到不和谐论坛

发送文件到不和谐论坛

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

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

回答如下:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论