问题描述
限时送ChatGPT账号..我正在尝试构建媒体集成,因此当我的新帖子到达媒体时,机器人会将帖子链接发送到不和谐频道.问题是我不知道如何从提要响应中获取数据,所以我可以在消息中使用它.收到来自提要的响应后,它看起来像这样.
I'm trying to build medium integration so when i new post arrives on medium, bot will then send the post link to the discord channel. The Problem is i don't know how to take data from the feed response so i can use it in the message. Once i receive the response from the feed, it looks like this.
title: 'Hopefully will be done soon',
description: '<p>Still making final testing!</p><img src="https://medium/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d067e89b091" width="1" height="1" alt="">',
summary: null,
date: 2021-09-12T01:26:33.000Z,
pubdate: 2021-09-12T01:26:33.000Z,
pubDate: 2021-09-12T01:26:33.000Z,
link: 'https://rasmont.medium/hopefully-will-be-done-soon-3d067e89b091?source=rss-762047c9bd39------2',
guid: 'https://medium/p/3d067e89b091',
author: 'RasmonT',
comments: null,
origlink: null,
image: {},
source: {},
categories: [],
enclosures: [],
'rss:@': {},
'rss:title': { '@': {}, '#': 'Hopefully will be done soon' },
'rss:link': {
'@': {},
'#': 'https://rasmont.medium/hopefully-will-be-done-soon-3d067e89b091?source=rss-762047c9bd39------2'
},
'rss:guid': { '@': [Object], '#': 'https://medium/p/3d067e89b091' },
'dc:creator': { '@': {}, '#': 'RasmonT' },
'rss:pubdate': { '@': {}, '#': 'Sun, 12 Sep 2021 01:26:33 GMT' },
'atom:updated': { '@': {}, '#': '2021-09-12T01:26:33.080Z' },
'content:encoded': {
'@': {},
'#': '<p>Still making final testing!</p><img src="https://medium/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d067e89b091" width="1" height="1" alt="">'
},
meta: {
'#ns': [Array],
'@': [Array],
'#xml': [Object],
'#type': 'rss',
'#version': '2.0',
title: 'Stories by RasmonT on Medium',
description: 'Stories by RasmonT on Medium',
date: 2021-09-12T01:39:23.000Z,
pubdate: 2021-09-12T01:39:23.000Z,
pubDate: 2021-09-12T01:39:23.000Z,
link: 'https://medium/@rasmont?source=rss-762047c9bd39------2',
xmlurl: 'https://medium/@rasmont/feed',
xmlUrl: 'https://medium/@rasmont/feed',
author: 'yourfriends@medium',
language: null,
favicon: null,
copyright: null,
generator: 'Medium',
cloud: [Object],
image: [Object],
categories: [],
'rss:@': {},
'rss:title': [Object],
'rss:description': [Object],
'rss:link': [Object],
'rss:image': [Object],
'rss:generator': [Object],
'rss:lastbuilddate': [Object],
'atom:link': [Array],
'rss:webmaster': [Object]
}
},
我试图解析响应,所以我可以从这样的响应中获取链接.
I tried to parse response so i can take the link from the response like this.
const link = JSON.parse(entry) console.log('FEED Call response:', link[link"]);
client.on('ready', () => {
watcher.on('new entries', function (entries) {
entries.forEach(function (entry) {
const link = JSON.parse(entry)
console.log('FEED Call response:', link["link"]);
console.log(entry)
})
})
watcher
.start()
.then(function (entries) {
console.log(entries)
})
.catch(function(error) {
console.error(error)
})
})
知道如何从响应中接收我想要的数据以便我可以在消息中使用它吗?
Any idea how can I receive the data I want from the response so I can use it in the message?
错误:SyntaxError:JSON 中位置 1 的意外标记 o
更新:我尝试使用它,但我不知道如何从响应中获取链接.
Updated: I tried to use this, however i don't know how to get the link from the response.
const link = JSON.stringify(entries)
console.log('FEED Call response:', link);
console.log(`Link:`, link[0].link)
回复是链接:[功能:链接]
推荐答案
您根本不必使用 JSON.parse
!接收到的数据已经是你想要的对象了.JSON.parse
自动将它的第一个参数设置为字符串,并使其更改为以下字符串:
You do not have to use JSON.parse
at all! The received data is already the object you want. JSON.parse
automatically sets its first argument as a string, and that makes it change to the following string:
"[object Object]"
JSON 允许 [
但不允许不带引号的 o.以下代码可以正常工作.
JSON allows the [
but not the o without a quotation mark. The following code will work just fine.
entries.forEach((entry) => {
console.log('FEED Call response:', entry);
console.log(entry[0].link)
})
这篇关于Discord.js 通过 feed-watcher 进行媒体集成,无法从更新中获取 feed 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论