-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (50 loc) · 1.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const venom = require('venom-bot');
const fs = require('fs')
const mime = require('mime-types')
venom.create().then((client)=>start(client)).catch((error)=>{
console.log(error)
});
function start(client){
console.log('Bot Ready')
client.onMessage(async (message)=>{
// cek apakah pesan yang dikirm mengandung media type gambar dengan caption '#bot sticker'
if (message.caption == '#bot sticker' && message.isMedia === true && message.isMMS === true && message.type=='image'){
const buffer = await client.decryptFile(message);
const fileName = `gambar.${mime.extension(message.mimetype)}`;
fs.writeFile(fileName,buffer,(err)=>{
if(!err){
console.log("file is created")
}else{
console.log(err)
}
});
// kirim notifikasi
await client
.sendText(message.from, 'Please wait...')
.then((result)=>{
console.log('Hasil: Pesan Terkirim')
})
.catch((error)=>{
console.log('Error saat mengirim: ', error);
})
// kirim sticker ke pengirim
await client
.sendImageAsSticker(message.from, fileName)
.then((result) => {
console.log('Hasil: Sticker Terkirim');
})
.catch((erro) => {
console.error('Error when sending: ', erro);
});
}
if (message.body =="#bot" ) {
await client
.sendText(message.from, 'Bot Ready')
.then((result)=>{
console.log('Hasil: Pesan Terkirim')
}).catch((error)=>{
console.log(error)
})
}
})
}