Vk-io: Terjadi kesalahan saat mencoba menghapus pengguna dari percakapan.

Dibuat pada 3 Des 2017  ·  20Komentar  ·  Sumber: negezor/vk-io

VK-IO - 4.0.0-alpha.4
Simpul - v9.2.0
Saya ingin mengirim 2 permintaan identik untuk menghapus peserta dari 2 percakapan.
1 permintaan berlalu, dan pada permintaan kedua saya menemukan kesalahan.

You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
FetchError: network timeout at: https://api.vk.com/method/messages.removeChatUser?access_token=ТОКЕН&v=5.69
    at Timeout._onTimeout (/home/vk/node_modules/node-fetch/lib/index.js:1272:13)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5)
Caught unhandledRejection: { FetchError: network timeout at: https://api.vk.com/method/messages.removeChatUser?access_token=ТОКЕН&v=5.69
    at Timeout._onTimeout (/home/vk/node_modules/node-fetch/lib/index.js:1272:13)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5)
  message: 'network timeout at: https://api.vk.com/method/messages.removeChatUser?access_token=ТОКЕН&v=5.69',
  type: 'request-timeout',
  stackframes:
   [ { file_name: '/home/vk/node_modules/node-fetch/lib/index.js',
       line_number: 1272 },
     { file_name: 'timers.js', line_number: 478 },
     { file_name: 'timers.js', line_number: 302 },
     { file_name: 'timers.js', line_number: 262 } ] }

Komentar yang paling membantu

Jika, setelah memulai ulang aplikasi, bot merespons untuk sementara waktu, dan kemudian berhenti, maka, kemungkinan besar, Long Poll yang harus disalahkan untuk semuanya, jika Anda tidak mengacaukan di tempat lain. Kemungkinan besar, Anda lupa untuk mengacaukan penanganan kesalahan permintaan yang tidak berhasil, dan server Long Poll VK sering kali suka memberikan 403, 500-503.

Pada saat yang sama, penting untuk diingat bahwa node-fetch mentransfer semua respons server (bahkan dengan kesalahan) ke blok then (), dilihat dari README:

Respons 3xx-5xx BUKAN kesalahan jaringan, dan harus ditangani saat itu ()

Jadi mungkin bug telah merayap di suatu tempat di sini , misalnya.

Saya bisa sangat salah , karena Saya tidak mempelajari kode perpustakaan, tetapi masalah paling umum dengan "mengabaikan" bot adalah operasi Long Poll yang tidak stabil, jadi semua kesalahan perlu diproses dan dihubungkan kembali ke server saat terjadi.

PS Namun, opsi terbaik adalah mencoba "mengemas" permintaan berurutan ini dalam kode users.get → messages.getChatUsers → messages.removeChatUser → message.send → users.get? menjadi satu execute -request. Ini akan lebih efisien dari sudut pandang menyimpan permintaan, karena diketahui ada batasan 3 permintaan per detik.

Semua 20 komentar

Dapatkah saya memiliki kode dan daftar opsi yang diinstal?

vk.api.messages.getChatUsers({chat_id: iChatID, fields: "online"}).then((chat) => {
    if (chat.indexOf(user.id) > -1) {
        vk.api.messages.removeChatUser({chat_id: iChatID, user_id: user.id}).then(() => {
            return message.send(`@id${user.id} (${user.first_name} ${user.last_name}) ${user.sex == 1 ? "удалена" : "удалён"} из беседы!`);
        });
    } else {
        vk.api.messages.removeChatUser({chat_id: iChatID, user_id: user.id}).then((remove) => {
            if (remove == 1) {
                return message.send(`@id${user.id} (${user.first_name} ${user.last_name}) принудительно ${user.sex == 1 ? "удалена" : "удалён"} из беседы!`);
            } else {
                vk.api.users.get({user_ids: user.id, name_case: 'acc', fields: 'sex'}).then(([user2]) => {
                    return message.send(`Не могу удалить @id${user2.id} (${user2.first_name} ${user2.last_name}), так как ${user2.sex == 1 ? "её" : "его"} нет в беседе.`);
                });
            }
        })
    }
});

Mungkin masalahnya ada di cek yang salah if (chat.indexOf(user.id) > -1)
Karena obrolan mengembalikan array objek.

Mungkin Anda harus melakukan ini?

vk.api.messages.removeChatUser({
    chat_id: iChatID,
    user_id: user.id
})
    .catch((error) => {
        if (error.code === 15) {
            return 0;
        }

        throw error;
    })
    .then((removed) => {
        if (removed === 1) {
            return message.send(`@id${user.id} (${user.first_name} ${user.last_name}) ${user.sex === 1 ? 'удалена' : 'удалён'} из беседы!`);
        }

        return message.send(`Не могу удалить @id${user.id} (${user.first_name} ${user.last_name}), так как ${user.sex === 1 ? 'её' : 'его'} нет в беседе.`);
    });

Saya menggunakan vk.api.users.get({user_ids: user.id, name_case: 'acc', fields: 'sex'}).then(([user2]) kedua kalinya karena kasus yang berbeda dalam pesan.

Lagi-lagi kesalahan yang tidak bisa dipahami, sudah tiba-tiba.

Caught unhandledRejection: { FetchError: network timeout at: https://api.vk.com/method/friends.getRequests?access_token=ТОКЕН&v=5.69
    at Timeout._onTimeout (/home/bots/vk/node_modules/node-fetch/lib/index.js:1272:13)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5)
  message: 'network timeout at: https://api.vk.com/method/friends.getRequests?access_token=ТОКЕН&v=5.69',
  type: 'request-timeout',
  stackframes: 
   [ { file_name: '/home/bots/vk/node_modules/node-fetch/lib/index.js',
       line_number: 1272 },
     { file_name: 'timers.js', line_number: 478 },
     { file_name: 'timers.js', line_number: 302 },
     { file_name: 'timers.js', line_number: 262 } ] }
Caught unhandledRejection: { FetchError: network timeout at: https://api.vk.com/method/friends.getRequests?access_token=ТОКЕН&v=5.69
    at Timeout._onTimeout (/home/bots/vk/node_modules/node-fetch/lib/index.js:1272:13)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5)
  message: 'network timeout at: https://api.vk.com/method/friends.getRequests?access_token=ТОКЕН&v=5.69',
  type: 'request-timeout' }

Dalam hal ini, bot duduk online tetapi tidak menanggapi pesan sama sekali.
Jika friends.getRequests itu ada di pengatur waktu, itu diperiksa setiap 30 detik.

Setelah reboot, masalahnya hilang.

Versi VK-IO - 4.0.0-alpha.5

Bot jatuh lagi, online, tetapi tidak menanggapi pesan.
Seperti yang saya pahami, Long Poll gagal

DEBUG=vk-io:updates , Anda harus mengumpulkan informasi terlebih dahulu.

Jika, setelah memulai ulang aplikasi, bot merespons untuk sementara waktu, dan kemudian berhenti, maka, kemungkinan besar, Long Poll yang harus disalahkan untuk semuanya, jika Anda tidak mengacaukan di tempat lain. Kemungkinan besar, Anda lupa untuk mengacaukan penanganan kesalahan permintaan yang tidak berhasil, dan server Long Poll VK sering kali suka memberikan 403, 500-503.

Pada saat yang sama, penting untuk diingat bahwa node-fetch mentransfer semua respons server (bahkan dengan kesalahan) ke blok then (), dilihat dari README:

Respons 3xx-5xx BUKAN kesalahan jaringan, dan harus ditangani saat itu ()

Jadi mungkin bug telah merayap di suatu tempat di sini , misalnya.

Saya bisa sangat salah , karena Saya tidak mempelajari kode perpustakaan, tetapi masalah paling umum dengan "mengabaikan" bot adalah operasi Long Poll yang tidak stabil, jadi semua kesalahan perlu diproses dan dihubungkan kembali ke server saat terjadi.

PS Namun, opsi terbaik adalah mencoba "mengemas" permintaan berurutan ini dalam kode users.get → messages.getChatUsers → messages.removeChatUser → message.send → users.get? menjadi satu execute -request. Ini akan lebih efisien dari sudut pandang menyimpan permintaan, karena diketahui ada batasan 3 permintaan per detik.

Masalah muncul setelah memperbarui perpustakaan dari versi 3 ke versi 4.
Sebelum itu, tidak ada masalah.

2017-12-08T08:27:13.947Z vk-io:updates http -->
2017-12-08T08:27:13.947Z vk-io:updates http <--
2017-12-08T08:27:13.947Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.947Z vk-io:updates http -->
2017-12-08T08:27:13.948Z vk-io:updates http <--
2017-12-08T08:27:13.948Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.948Z vk-io:updates http -->
2017-12-08T08:27:13.948Z vk-io:updates http <--
2017-12-08T08:27:13.948Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.949Z vk-io:updates http -->
2017-12-08T08:27:13.949Z vk-io:updates http <--
2017-12-08T08:27:13.949Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.949Z vk-io:updates http -->
2017-12-08T08:27:13.947Z vk-io:updates http -->
2017-12-08T08:27:13.947Z vk-io:updates http <--
2017-12-08T08:27:13.947Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.947Z vk-io:updates http -->
2017-12-08T08:27:13.948Z vk-io:updates http <--
2017-12-08T08:27:13.948Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.948Z vk-io:updates http -->
2017-12-08T08:27:13.948Z vk-io:updates http <--
2017-12-08T08:27:13.948Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.949Z vk-io:updates http -->
2017-12-08T08:27:13.949Z vk-io:updates http <--
2017-12-08T08:27:13.949Z vk-io:updates longpoll update [ 9, -286131                      123, 1, 1512721234 ]
2017-12-08T08:27:13.949Z vk-io:updates http -->

Kemudian bot berhenti dan kembali mengabaikan semua pesan.

Saya telah mengunggah pembaruan, coba dengan itu.

Dan sekarang situasinya berbeda, saya menulis pesan dan pesan muncul di log bot, tetapi dia tidak menanggapi perintah itu.

2017-12-08T14:44:02.580Z vk-io:updates http -->
2017-12-08T14:44:02.581Z vk-io:updates http <--
2017-12-08T14:44:02.581Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.581Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.581Z vk-io:updates http -->
2017-12-08T14:44:02.581Z vk-io:updates http <--
2017-12-08T14:44:02.581Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.581Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.581Z vk-io:updates http -->
2017-12-08T14:44:02.582Z vk-io:updates http <--
2017-12-08T14:44:02.582Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.582Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.582Z vk-io:updates http -->
2017-12-08T14:44:02.582Z vk-io:updates http <--
2017-12-08T14:44:02.582Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.583Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.583Z vk-io:updates http -->
2017-12-08T14:44:02.583Z vk-io:updates http <--
2017-12-08T14:44:02.583Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.583Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.583Z vk-io:updates http -->
2017-12-08T14:44:02.584Z vk-io:updates http <--
2017-12-08T14:44:02.584Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.584Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.584Z vk-io:updates http -->
2017-12-08T14:44:02.584Z vk-io:updates http <--
2017-12-08T14:44:02.584Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.584Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.584Z vk-io:updates http -->
2017-12-08T14:44:02.585Z vk-io:updates http <--
2017-12-08T14:44:02.585Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.585Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.585Z vk-io:updates http -->
2017-12-08T14:44:02.585Z vk-io:updates http <--
2017-12-08T14:44:02.585Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.585Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.585Z vk-io:updates http -->
2017-12-08T14:44:02.586Z vk-io:updates http <--
2017-12-08T14:44:02.586Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.586Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.586Z vk-io:updates http -->
2017-12-08T14:44:02.586Z vk-io:updates http <--
2017-12-08T14:44:02.586Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.586Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.587Z vk-io:updates http -->
2017-12-08T14:44:02.587Z vk-io:updates http <--
2017-12-08T14:44:02.587Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.587Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.587Z vk-io:updates http -->
2017-12-08T14:44:02.588Z vk-io:updates http <--
2017-12-08T14:44:02.588Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.588Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.588Z vk-io:updates http -->
2017-12-08T14:44:02.588Z vk-io:updates http <--
2017-12-08T14:44:02.588Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.588Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.588Z vk-io:updates http -->
2017-12-08T14:44:02.589Z vk-io:updates http <--
2017-12-08T14:44:02.589Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.589Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.589Z vk-io:updates http -->
2017-12-08T14:44:02.589Z vk-io:updates http <--
2017-12-08T14:44:02.589Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.589Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.589Z vk-io:updates http -->
2017-12-08T14:44:02.590Z vk-io:updates http <--
2017-12-08T14:44:02.590Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.590Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.590Z vk-io:updates http -->
2017-12-08T14:44:02.590Z vk-io:updates http <--
2017-12-08T14:44:02.590Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.590Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.590Z vk-io:updates http -->
2017-12-08T14:44:02.591Z vk-io:updates http <--
2017-12-08T14:44:02.591Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.591Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.591Z vk-io:updates http -->
2017-12-08T14:44:02.591Z vk-io:updates http <--
2017-12-08T14:44:02.591Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.591Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.591Z vk-io:updates http -->
2017-12-08T14:44:02.592Z vk-io:updates http <--
2017-12-08T14:44:02.592Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.592Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.592Z vk-io:updates http -->
2017-12-08T14:44:02.592Z vk-io:updates http <--
2017-12-08T14:44:02.592Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.592Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.592Z vk-io:updates http -->
2017-12-08T14:44:02.593Z vk-io:updates http <--
2017-12-08T14:44:02.593Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.593Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.593Z vk-io:updates http -->
2017-12-08T14:44:02.593Z vk-io:updates http <--
2017-12-08T14:44:02.593Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.593Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]
2017-12-08T14:44:02.593Z vk-io:updates http -->
2017-12-08T14:44:02.594Z vk-io:updates http <--
2017-12-08T14:44:02.594Z vk-io:updates longpoll update [ 7, 2000000004, 84955 ]
2017-12-08T14:44:02.594Z vk-io:updates longpoll update [ 4,
  84959,
  532497,
  2000000004,
  1512744139,
  '/ping',
  { from: '46199828' } ]

Dan kode itu sendiri?

vk.auth.implicitFlowUser().run().then((response) => {
    vk.setToken(response.token);
    vk.updates.startPolling();
});

vk.updates.on('message', (message, next) => {
    if (!message.text || message.from.id != 2000000004 && message.from.id != ***) return;
    let command = message.text.split(" ")[0].slice(1).toLowerCase()
    if (command === 'ping') {
        vk.api.users.get({user_ids: message.payload.user_id}).then(([user]) => {
            message.send(`Pong!\n@id${message.payload.user_id} (${user.first_name}) 😉`);
        });
    }
});

Maaf jawabannya panjang :)

Saya harus segera mengatakan bahwa Anda tidak boleh langsung mengakses properti konteks. Karena untuk jenis penerimaan data yang berbeda bisa saja berbeda, dan Anda juga tidak perlu setiap kali login ulang, sebaiknya tidak jika tidak ingin mendapatkan IP ban dari VK atau hanya captcha.
Anda juga dapat mengikuti bot sederhana

Menurut kode, saya akan mengatakan bahwa itu adalah pekerja, masalahnya ternyata hanya panggilan langsung ke from.id . Jika Anda perlu memeriksa ID obrolan, Anda dapat menggunakan context.getChatId() !== 4 && context.getUserId() !== ***

tidak perlu login lagi setiap saat

Bisakah Anda memberi tahu saya di mana kesalahan otorisasi saya?
Dan bagaimana melakukannya dengan benar.

Sebaiknya simpan token setelah otorisasi dan gunakan dari konfigurasi.

Masalah polling terkait dengan c # 43

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

SOS
helix-team picture helix-team  ·  4Komentar

ProgrammingLife picture ProgrammingLife  ·  9Komentar

AndreiSoroka picture AndreiSoroka  ·  6Komentar

nitreojs picture nitreojs  ·  3Komentar

alexey2baranov picture alexey2baranov  ·  8Komentar