Berikut adalah contoh kode untuk membuat WhatsApp bot menggunakan Node.js dengan adiwajshing baileys untuk mengunduh file dari yande.re menggunakan metode query dan link:

const { WAConnection, MessageType } = require('@adiwajshing/baileys');
const axios = require('axios');

const sessionFile = './session.json'; // file untuk menyimpan session WhatsApp

const downloadFile = async (url) => {
  const response = await axios.get(url, { responseType: 'arraybuffer' });
  return response.data;
};

const handleMessage = async (message) => {
  try {
    if (message.mimetype) {
      const mediaData = await downloadFile(message.url);
      // Simpan file media atau lakukan operasi lain
      console.log('Media file:', message.filename);
    } else if (message.body.startsWith('!yandere')) {
      const query = message.body.split(' ')[1];
      const apiUrl = `https://yande.re/post.json?limit=1&tags=${query}`;
      
      const response = await axios.get(apiUrl);
      const imageUrl = response.data[0].file_url;
      const caption = response.data[0].tags;
      
      const mediaData = await downloadFile(imageUrl);
      // Kirim gambar dengan caption
      await conn.sendMessage(message.from, mediaData, MessageType.image, { caption });
    }
  } catch (error) {
    console.error('Error:', error);
  }
};

// Buat instance WAConnection
const conn = new WAConnection();
conn.autoReconnect = true;

// Event saat mendapat pesan baru
conn.on('chat-update', async (chat) => {
  if (chat.messages && chat.count) {
    const message = chat.messages.all()[0];
    await handleMessage(message);
  }
});

// Jalankan WhatsApp bot
const runBot = async () => {
  await conn.loadAuthInfo(sessionFile); // Load session WhatsApp jika ada

  // Membuat koneksi WhatsApp
  await conn.connect();

  // Simpan session WhatsApp
  conn.on('credentials-updated', () => {
    const authInfo = conn.base64EncodedAuthInfo();
    fs.writeFileSync(sessionFile, JSON.stringify(authInfo, null, '\t'));
  });

  console.log('WhatsApp bot sedang berjalan!');
};

runBot().catch((error) => console.error(error));

Pastikan Anda telah menginstal paket @adiwajshing/baileys dan axios menggunakan perintah npm install @adiwajshing/baileys axios

buatkan saya downloader yandere dengan metode query dan link buat dalam bentuk whatsapp bot nodejs dengan adiwajshing baileys

原文地址: https://www.cveoy.top/t/topic/hNeR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录