javascript - 如果我从 .json 中提取具有自动重定向的 url,如何使输出成为我将被重定向到的页面?- Javascript
问题描述
有问题的网址不是来自我自己的网站。
此代码使用 discord.js,用于让机器人从 reddits .json 中提取帖子的 url。它不适用于 nsfw gfycat 链接,因为它们现在都自动重定向到它们在 gifdeliverynetwork 中的新位置。
if(cmd == `${prefix}r`){
if(message.channel.nsfw){
request("https://www.reddit.com/r/" + args + "/top/.json?t=all&limit=100", function(error, response, body){
let msg = JSON.parse(body);
try{
let imgurl = msg["data"]["children"][Math.floor((Math.random() * 100) + 0)]["data"]["url"];
if (imgurl.includes('gfycat')) {
return message.channel.send(imgurl + "\nr **" + args + "** requested by **" + message.author.tag + "**" + "\n***can't see the post?** - discord doesn't support most gfycat links but you can still click it!*");
} else {
return message.channel.send(imgurl + "\nr **" + args + "** requested by **" + message.author.tag + "**");}}
catch{
return message.channel.send("Error getting data from the subreddit - **" + args + "**");
}
});
} else {
return message.channel.send("This channel is not set to nsfw. Please use <rp");
}
}
解决方案
推荐阅读
- c# - 值不能为空。(参数“连接字符串”)
- php - 如何使用 symfony 5 摆脱国际弃用消息
- python - 如何生成这些 True 和 False 列表?
- reactjs - 从反应原生导航中删除元素
- javascript - YouTube 嵌入式视频 JavaScript API 无法在 DOMWindow 上执行 postMessage 提供的目标来源不匹配
- php - Wordpress 中不需要的 301 重定向
- matlab - 有没有办法在创建矩阵时使用“for循环”
- reactjs - 使轴线变灰或降低不透明度
- ansible - 如何在ansible中打印多行字符串输出中的项目列表
- c++ - 如何在 C++/WinRT 中制作矢量的深层副本?