久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 亚洲综合字幕 | 亚洲欧美日韩在线不卡 | 精品国产欧美一区二区三区成人 | 免费一级片| 亚洲综合伊人 | av乱码 | 少妇性l交大片免费一 | 神马久久久久久久久久 | 久久精品小视频 | hsck成人网 | 欧美一区二区三区小说 | 亚洲国产片| 中文字幕在线观看视频一区 | 色综合一区二区 | 日韩在线一区二区三区 | 日韩三级免费网站 | 色视频网站 | 99精品欧美一区二区三区 | 日韩在线观看中文字幕 | 91精品久久久久久综合五月天 | 亚洲一区国产精品 | 成人免费视频网站在线看 | 亚洲在线成人 | 久久国产欧美日韩精品 | 在线播放91 | 免费观看一级特黄欧美大片 | 亚洲中国字幕 | 亚洲精品第一 | 亚洲精品乱码久久久久久久久 | 波多野结衣一区二区三区在线观看 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 天天精品综合 | 亚洲毛片 | 亚洲最大福利网 | 亚洲精品电影在线观看 | h小视频| 激情国产在线 | 欧美精品一区二区三区一线天视频 | 一级片av | 91网站视频在线观看 | 99热视|