ajustar esse script const { Client, GatewayIntentBits } = require("discord.js"); const…
- User
ajustar esse script
const { Client, GatewayIntentBits } = require("discord.js"); const fs = require("fs").promises; const path = require("path");
// Crie um cliente Discord const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], });
const token = "MTE2MzQ3NzYzNjQ4MDI1ODE1OA.GBHSJD.MafOyDspP9uk_rz6_pCTKmubdCGtsiANY32M50";
async function setupBot(video, vUserName, channelId) { client.login(token); client.on('ready', async () => { console.log(Bot está online como {client.user.tag}); if (video) { const videoPath = path.join(__dirname,{video}.mp4); console.log(videoPath); try { await fs.access(videoPath); const videoBuffer = await readLocalVideo(videoPath); if (videoBuffer) { await uploadVideoToChannel(videoBuffer, channelId, vUserName, videoPath); } else { console.error('Falha ao ler o vídeo da pasta local.'); } } catch (error) { console.error(Erro ao acessar o vídeo da pasta local: ${error.message}); } finally { client.destroy(); console.log('Bot client destroyed.'); } } }); }
async function readLocalVideo(filePath) { try { const videoBuffer = await fs.readFile(filePath); return videoBuffer; } catch (error) { console.error(Erro ao ler o vídeo da pasta local: ${error.message}); return null; } }
async function uploadVideoToChannel(videoBuffer, channelId, text, videoPath) { const channel = await client.channels.fetch(channelId); // Certifique-se de que o canal existe e é um canal de texto if (channel && channel.isTextBased()) { try { // Use o método send com um await channel.send({ // content: text, files: [ { attachment: videoBuffer, name: "video.mp4", }, ], }); // após o upload setTimeout(async () => { await fs.unlink(videoPath); console.log(Vídeo local deletado: undefined{error.message}); } } else { console.error(Canal ${channelId} canal de texto.); } }
module.exports = { setupBot };
quando o camando setupBot , atualemente ele apenas envia uma vez e nas proximas nao envia
- Assistant