简体   繁体   中英

How to display information from a website on my discord bot?

Im building a discord bot(Javascript, Node.js, Discord.js) which is based on a game (a online multiplayer).So, im pretty much done developing the bot except for one thing which I really wish I could add. So, this game has some highscores which can be viewed here - https://www.hzgaming.net/high.php . So, I want to display those highscores (Highscore money - https://www.hzgaming.net/high.php?scores=money ) (Highscore materials - https://www.hzgaming.net/high.php?scores=materials ) and all those. So, what I would like to have is..when a user types a cmd like '!highscore money', it should show the highscore available on that website link I gave above, and similarly..when they use '!highscore materials' it should show the highscore of materials from that link respectivly. I want it to be from that link because, it keeps on changing and gets updated. Also, im pretty sure its possible because, there is a similar bot which shows the same thing as I explained. I hope you understood what I meant. I would really love to get an answer for this, also it would be great if an example code is provided with the answer so that its easy to understand.

An example for the cmd is given below -

user - !highscore money BOT - Money High Scores

  1. Celia_Fernandz - $41,085,610 total wealth
  2. Armando_Domrani - $40,204,664 total wealth
  3. Sergio_Box - $38,199,486 total wealth
  4. Tony_Sativa - $30,193,261 total wealth
  5. Aminox_Trigui - $28,052,188 total wealth
  6. Ben_Martin - $23,439,003 total wealth
  7. Daryl_Grimes - $17,128,518 total wealth
  8. Luccas_Von_Koening - $16,457,964 total wealth
  9. Charlie_Hustle - $14,452,056 total wealth
  10. Kevin_Maddox - $13,630,605 total wealth

user- !highscore materials BOT - 1. Chapo_Diamond - 5,749,300 materials 2. Van_Damme - 4,923,046 materials 3. Brandon_Heath_Tsung - 3,906,395 materials 4. Armando_Domrani - 3,241,925 materials 5. Tazz_Equinox - 3,187,045 materials 6. Danny_Ted - 2,868,088 materials 7. Jack_Paterson - 2,748,249 materials 8. John_Dixon - 2,548,250 materials 9. Gab_Alphonse - 2,252,285 materials 10. Don_Thomax - 2,131,177 materials (( ALL THE REPLY BY THE BOT WILL BE EMBEDS )) (yea, so somehow those values should keep on updating, thats why I gave the link above)

Pls note that the code should be javascript using discord.js and node.js. Thank you <3 :)

I'm not sure if that's possible because of the "Just checking your computer, this will only take a few seconds" page that will always pop up (for DDoS protection). For example, this is what I got in my console after requesting some data:

<!DOCTYPE html>
<html>
        <head>
                <meta charset="UTF-8">
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
                <meta name="robots" content="noindex, nofollow">
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
                <meta http-equiv="refresh" content="12">
                <link rel="Shortcut Icon" href="https://www.hzgaming.net/favicon.ico" type="image/x-icon">
                <title>Just a moment...</title>
                <style>@font-face{font-family:Open Sans;font-style:normal;font-weight:400;font-display:swap;src:local("Open Sans Regular"),local("OpenSans-Regular"),url(data:font/woff2;base64,
d09GMgABAAAAACjgAA4AAAAAUhQAACiIAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGiIbEBwaBmAAZBEQCoGANONLC4
M8AAE2AiQDhnAEIAWDWgeQShv4QBXjmFXAxsEAi709IypHX42iQhIH/39MoGOIFG6KqtsXWLsNGTEJswgLuVELAuzt
6BPcQHcKGcv5HKXdi+eKlYT6O/H7D3cgR+jqXNVLasoPuSn55q2H3pbvh3OAu9IvBQY5QmOf5EL/td9nz5tz7szuhl
FHoURhUQJqVpEko1I+Ki4WZRSx2vo+qLaiHszxbb7Ne0BkhgdhTe1mgqThm6figcxKku0p+W2vqybIl4ofbmvDwzr/

// and so on... for a very long time.

I don't think there's a way to get past this, but in the miraculous chance you find a way, this is how I would get the needed data:

// you should use this npm package - https://www.npmjs.com/package/node-fetch
const fetch = require('node-fetch');

fetch('https://www.hzgaming.net/high.php?scores=money')
      .then((res) => res.text())
      .then((body) => console.log(body));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM