R
R
rama_jecboom2020-11-23 14:28:49
Node.js
rama_jecboom, 2020-11-23 14:28:49

How to make discord bot show website status?

Good afternoon, how can I make the discord bot send the status about the site?

Let's say there is google.com, you need that when you write a command (for example: !status ) it shows the website's response time, etc.
And for example, when the site went down, it was written that the server was not online, etc.

But the problem is that the site does not have a status page, etc., and you need to get information from somewhere.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ettychel, 2020-11-23
@rama_jecboom

rama_jecboom , make a curl request to the desired site, if it responds with 200 status, then the site is available.
For example, you hang a handler on the !status command, where name is the resource whose status is to be found out.
You must also have a json file, or some other file or source of information with site names and their urls, for example:

/* urlBase.json */
[
  {
    "name": "google",
    "url": "https://google.com"
  },
  {
    "name": "vk",
    "url": "https://vk.com"
  }
]

Accordingly, in the handler, you look for the object you need in the array and send it to the method that will request the status
/* ... */
import urlBase from "./urlBase.json"

/*...*/

const targetSite = urlBase.find( e => e.name === name )

return getTargetSiteStatus(targetSite)

But the status request method itself is done using the node-fetch package and https, I leave the implementation to you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question