久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有 meme subreddit 的 Discord.js meme 命令將圖像返回

Discord.js meme command with meme subreddit returns image as 403 forbidden(帶有 meme subreddit 的 Discord.js meme 命令將圖像返回為 403 禁止)
本文介紹了帶有 meme subreddit 的 Discord.js meme 命令將圖像返回為 403 禁止的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在制作一個 meme 命令,從 meme subreddit 發送一個隨機 meme,在發現除了嵌入中的實際圖像之外的所有內容后,我將圖像記錄到控制臺并返回 403 錯誤.如果有人能夠提供幫助,將不勝感激.

I'm making a meme command that sends a random meme from the meme subreddit and after discovering everything except the actual image in embed was working I logged the image to console and it returned a 403 error. If anyone is able to help it would be greatly appreciated.

代碼:

const https = require('https');
const Discord = require('discord.js');
const url = 'https://www.reddit.com/r/meme/hot/.json?limit=100'

module.exports = {
    name: 'meme',
    description: 'sends meme',
    execute(message, args) {

        https.get(url, (result) => {
            var body = ''
            result.on('data', (chunk) => {
                body += chunk
            })

            result.on('end', () => {
                var response = JSON.parse(body)
                var index = response.data.children[Math.floor(Math.random() * 99) + 1].data

                if (index.post_hint !== 'image') {

                    var text = index.selftext
                    const textembed = new Discord.MessageEmbed()
                        .setTitle(subRedditName)
                        .setColor(9384170)
                        .setDescription(`[${title}](${link})

${text}`)
                        .setURL(`https://reddit.com/${subRedditName}`)

                    message.channel.send(textembed)
                }

                var image = index.preview.images[0].source.url
                var title = index.title
                var link = 'https://reddit.com' + index.permalink
                var subRedditName = index.subreddit_name_prefixed

                if (index.post_hint !== 'image') {
                    const textembed = new Discord.RichEmbed()
                        .setTitle(subRedditName)
                        .setColor(9384170)
                        .setDescription(`[${title}](${link})

${text}`)
                        .setURL(`https://reddit.com/${subRedditName}`)

                    message.channel.send(textembed)
                }
                console.log(image);
                const imageembed = new Discord.MessageEmbed()
                    .setTitle(subRedditName)
                    .setImage(image)
                    .setColor(9384170)
                    .setDescription(`[${title}](${link})`)
                    .setURL(`https://reddit.com/${subRedditName}`)
                message.channel.send(imageembed)
            }).on('error', function (e) {
                console.log('Got an error: ', e)
            })
        })
    },


}

推薦答案

我試過你的代碼,看到圖片URL中的&被編碼為&(示例:https://preview.redd.it/z8jsjzvkhq051.jpg?auto=webp&s=bb492d4861f48b62da806584f26bcc15f4d6663a)Redd.it 無法理解并返回一個403 錯誤.

I have tried your code and have seen that the & in the image URL is encoded to & (example: https://preview.redd.it/z8jsjzvkhq051.jpg?auto=webp&s=bb492d4861f48b62da806584f26bcc15f4d6663a) that Redd.it can't understand it and returns a 403 error.

只需將圖片 URL 中的 & 替換為 & 即可.

Just replace the & to & in the image URL and it worked for me.

const https = require('https');
const Discord = require('discord.js');
const url = 'https://www.reddit.com/r/meme/hot/.json?limit=100'

module.exports = {
    name: 'meme',
    description: 'sends meme',
    execute(message, args) {

        https.get(url, (result) => {
            var body = ''
            result.on('data', (chunk) => {
                body += chunk
            })

            result.on('end', () => {
                var response = JSON.parse(body)
                var index = response.data.children[Math.floor(Math.random() * 99) + 1].data

                if (index.post_hint !== 'image') {

                    var text = index.selftext
                    const textembed = new Discord.MessageEmbed()
                        .setTitle(subRedditName)
                        .setColor(9384170)
                        .setDescription(`[${title}](${link})

${text}`)
                        .setURL(`https://reddit.com/${subRedditName}`)

                    message.channel.send(textembed)
                }

                var image = index.preview.images[0].source.url.replace('&', '&')
                var title = index.title
                var link = 'https://reddit.com' + index.permalink
                var subRedditName = index.subreddit_name_prefixed

                if (index.post_hint !== 'image') {
                    const textembed = new Discord.RichEmbed()
                        .setTitle(subRedditName)
                        .setColor(9384170)
                        .setDescription(`[${title}](${link})

${text}`)
                        .setURL(`https://reddit.com/${subRedditName}`)

                    message.channel.send(textembed)
                }
                console.log(image);
                const imageembed = new Discord.MessageEmbed()
                    .setTitle(subRedditName)
                    .setImage(image)
                    .setColor(9384170)
                    .setDescription(`[${title}](${link})`)
                    .setURL(`https://reddit.com/${subRedditName}`)
                message.channel.send(imageembed)
            }).on('error', function (e) {
                console.log('Got an error: ', e)
            })
        })
    },
}

這篇關于帶有 meme subreddit 的 Discord.js meme 命令將圖像返回為 403 禁止的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 一区二区在线 | 99精品一区二区 | 麻豆久久久久久 | 一级少妇女片 | av免费观看网站 | 一区二区国产精品 | 在线观看日韩精品视频 | 欧美精品网站 | 久久久夜色精品亚洲 | 天天曰夜夜操 | 国产欧美一区二区三区日本久久久 | 91影视 | 91精品国产综合久久久久久蜜臀 | 精品久久久久久久人人人人传媒 | 国产精品久久国产精品 | 99久久久久久久久 | 欧美a级成人淫片免费看 | 久久亚洲视频 | 精品欧美一区二区三区 | 好姑娘影视在线观看高清 | 欧美8一10sex性hd | 美女国内精品自产拍在线播放 | 天天干亚洲| 中文字幕在线播放不卡 | www.日本精品| 国产乱码精品1区2区3区 | 视频一区在线 | 欧美中文字幕在线观看 | 中文无码日韩欧 | 久久精品成人 | 日本成人片在线观看 | 欧美中文字幕在线观看 | 欧美日韩视频在线第一区 | 欧美xxxx日本 | 久久久久久女 | 精品国产乱码久久久久久中文 | 中文字幕在线第一页 | 欧美无乱码久久久免费午夜一区 | 日韩一区二区免费视频 | 中文字幕免费 | 国产精品美女久久久久aⅴ国产馆 |