【问题标题】:Invalid Form Body embed.image.url: Could not interpret "{}" as string无效的表单正文 embed.image.url:无法将“{}”解释为字符串
【发布时间】:2020-10-27 23:43:14
【问题描述】:

我正在尝试创建一个 meme 命令,它从 reddit 发布 meme

这是发布表情包的命令:

const randompuppy = require("random-puppy");

    if(message.content.startsWith(prefix + 'meme')){
        const subredddits = ["dankmeme", "meme", "me_irl"];
        // Grab a random property from the array
        const random = subredddits[Math.floor(Math.random() * subredddits.length)];

        // Get a random image from the subreddit page
        const image = randompuppy(random);
        const embed = new RichEmbed()
            .setColor("RANDOM")
            .setImage(image)
            .setTitle(`From /r/${random}`)
            .setFooter(`© Extendo Selfbot | prefix: ${prefix} | Made By 7teen#1646`)
            .setURL(`https://reddit.com/r/${random}`);
        message.channel.send(embed);
    }

这是错误

(node:2180) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.image.url: Could not interpret "{}" as string.
    at C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\Discord Bots\Testing\SELFBOT\extendo v2\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
    at C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\Discord Bots\Testing\SELFBOT\extendo v2\node_modules\snekfetch\src\index.js:215:21
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:2180) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2180) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我们将不胜感激!

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    根据random-puppy npm 页面:

    randomPuppy(subreddit)

    返回一个promise 用于来自所选子reddit 的随机图片网址。警告:我们不能保证它会是小狗的形象!

    randomPuppy 函数不返回字符串,而是返回一个解析字符串的承诺。要使用它,您可以await 承诺,或使用.then() 函数。

    // when using `await`, always make sure the function is async!
    // client.on('message', async (message) => {...}
    //                      ^^^^^
    
    const image = await randompuppy(random);
    const embed = new RichEmbed()
     .setColor('RANDOM')
     .setImage(image)
     .setTitle(`From /r/${random}`)
     .setFooter(`© Extendo Selfbot | prefix: ${prefix} | Made By 7teen#1646`)
     .setURL(`https://reddit.com/r/${random}`);
    message.channel.send(embed);
    
    // or:
    
    randompuppy(random).then((image) => {
     const embed = new RichEmbed()
      .setColor('RANDOM')
      .setImage(image)
      .setTitle(`From /r/${random}`)
      .setFooter(`© Extendo Selfbot | prefix: ${prefix} | Made By 7teen#1646`)
      .setURL(`https://reddit.com/r/${random}`);
     message.channel.send(embed);
    });
    

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多