A
A
anubis4652021-10-30 15:11:08
Node.js
anubis465, 2021-10-30 15:11:08

How can I make an automatic check every 10 seconds?

How can I set the interval to check the status of the payment every 10 seconds, and if the payment is successful, send a message to the channel and disable the check.

client.on('messageCreate', (message) => { //whenever a message is sent
  if (message.content.startsWith(prefix + 'оплата')) { //if it contains an invite link

 if (!message.channel.name === 'DM') return message.channel.send("Эта команда работает только в личных сообщениях бота!")
 const nick = message.content.split(" ").splice(1).join(" ")
if (!nick) return message.author.send("Укажите ваш никнэйм!")
    const params = {
        publicKey,
        amount: "1.00" ,
        currency: 'RUB',
        billId: qiwiApi.generateId(),
        comment: "Оплата спонсорки на месяц."
       // successUrl: 'https://merchant.com/payment/success?billId=lougeghuu'
    };
    const link = qiwiApi.createPaymentForm(params);
      const PAYID  = new Discord.MessageEmbed()
      .setAuthor("GUARD QIWI", "https://media.discordapp.net/attachments/899699390082601011/903958418166005760/871755380349341797.png")
      .setTitle("Выставление счет")
      .setDescription(`
      Сумма платежа: ${params.amount} ${params.currency}
      Ваш платежный ID: ||${params.billId}||
      НИКОМУ НЕ СООБЩАЙТЕ ВАШ ПЛАТЕЖНЫЙ ID!
      
      Ссылка оплаты: [Нажмите сюда](${link})`)
      message.author.send({ embeds: [PAYID] })
    

        // generate random number between 1 and list length.
    
        qiwiApi.getBillInfo(params.billId).then(data => { // получаем данные о счете
          // if (error) {message.channel.send("Произошла ошибка! Возможно вы не оплатили счет!")}
           if (data.status.value == "PAID") { // Если статус счета оплачен (PAID)
             var Rcon = require('rcon');

             var conn = new Rcon("**");
             
             conn.on('auth', function() {
               // You must wait until this event is fired before sending any commands,
               // otherwise those commands will fail.
               console.log("Authenticated");
               console.log("Sending command: SPONSOR!")
               conn.send(`**`)
             


             }).on('response', function(str) {
               console.log("Response: " + str);
             }).on('error', function(err) {
               console.log("Error: " + err);
             }).on('end', function() {
               console.log("Connection closed");
               process.exit();
             });
             
             conn.connect();
             const embed = new Discord.MessageEmbed()
.setAuthor("GUARD QIWI", "https://media.discordapp.net/attachments/899699390082601011/903958418166005760/871755380349341797.png")
.setDescription(`Ваш счет оплачен!`)
               message.author.send({embeds: [embed]})
              }
           else { 
             console.log(`${message.author.id} еще не оплатил счет.`)

           }}).catch(e => {
            console.log(`${message.author.id} еще не оплатил счет.`)
           
           })}})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RealRzhaka, 2021-10-31
@anubis465

Use setInterval every 10 seconds, upon successful payment, delete the timer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question