M
M
MrZillaGold2019-03-22 16:17:55
JavaScript
MrZillaGold, 2019-03-22 16:17:55

How to display the answer not in the console, but in a line?

vk.updates.hear(/^(?:rcon)\s?([^]+)?/i, (message) => { 
  return rcon.connect().then(() => {
  return rcon.send(`${message.$match[1]}`); 
}).then(res => {
  console.log(res);
}).then(() => {
  return message.send(`ОТВЕТ СЮДА`);
  return rcon.disconnect();
  })
});

I need to output the response from return rcon.send to return message.send

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
inzeppelin, 2019-03-22
@MrZillaGold

I don't get it either, but I'm thinking like this

vk.updates.hear(/^(?:rcon)\s?([^]+)?/i, (message) => {
  return rcon.connect()
    .then(() => {
      return rcon.send(`${message.$match[1]}`);
    })
    .then((res) => {
      console.log(res);
      // После консоль лога сделать return
      return res;
    })
    .then((res) => {
      // Два return'a работать не будут. Нужно оставить что-то одно
      message.send(res);
      return rcon.disconnect();
    });
});

Or even better:
vk.updates.hear(/^(?:rcon)\s?([^]+)?/i, (message) => {
  return rcon.connect()
    .then(() => rcon.send(`${message.$match[1]}`))
    .then((res) => {
      console.log(res);
      message.send(res);
      return rcon.disconnect();
    });
});

I
Igor, 2019-03-22
@aM-aM

Perhaps I did not understand the question, but maybe this will help.

let cachedMessage = '';
vk.updates.hear(/^(?:rcon)\s?([^]+)?/i, (message) => {
  cachedMessage = message;
  return rcon.connect().then(() => {
  return rcon.send(`${message.$match[1]}`); 
}).then(res => {
  console.log(res);
}).then(() => {
  return message.send(cachedMessage);
  return rcon.disconnect();
  })
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question