Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

node.js - Easy way to have my Discord bot read the contents of a webpage?

First time poster and inexperienced coder here. I've wanted to make my Discord bot read the Binding of Isaac wiki to send information such as item descriptions when the user sends a command such as "!effect (itemname)"

Example:

User: !effect diplopia
Bot: Effect: Duplicates all pickups and pedestal items in the current room, then disappears.

Link used in example: https://bindingofisaacrebirth.gamepedia.com/Diplopia

I haven't tried too much since I don't know where to start, but I have looked around for quite a bit but it all either seems to complicated for someone of my skill level or unrelated to what I'm trying to do.

Any help is appreciated. Thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Welcome to coding! To read an external web page such as https://bindingofisaacrebirth.gamepedia.com/Diplopia, you would need an HTTP client library. One of the most popular at the moment is needle.

A simple example of how you can the module is is shown below. The link to the npm module above documents the library in detail.

npm i needle
const needle = require('needle');

needle.get('http://www.example.com', (error, response) => {

  if (!error && response.statusCode == 200)
    console.log(response.body);

});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...