javascript - 无效的表单正文 embed.image.url:无法将“{}”解释为字符串
问题描述
我正在尝试创建一个 meme 命令,它从 reddit 发布 meme
这是 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.
帮助将不胜感激!
解决方案
根据随机小狗npm 页面:
randomPuppy(subreddit)
从选定的 subreddit返回一个
promise
随机图像 url。警告:我们不能保证它会是一只小狗的形象!
该randomPuppy
函数不返回字符串,而是返回解析字符串的承诺。要使用它,您可以使用await
Promise 或使用.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);
});
推荐阅读
- html - CSS 定位在父元素之外
- docxtemplater - Docxtemplater 可变数据键
- typescript - Ionic BLE 写入其他设备
- pine-script - 根据值绘制不同颜色的图表
- php - 使用 PHP 上传多个文件并在 CSS 中存储表单
- javascript - 如何在矩形(three.js)中切孔?
- matlab - 慢速数据游标回调期间的数据提示标签不正确
- javascript - 如何使用 jQuery AJAX 检查 PHP 数据?
- chef-infra - 在 Chef-Client 运行时更新 Chef 属性
- javascript - Javascript 中的动态导入是否会改变导入库/组件的方式?