我正在尝试执行一个meme命令,在该命令中它会发布来自reddit的memes
这是用于模因发布的命令:
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.
我们将不胜感激!
答案 0 :(得分:0)
根据random-puppy npm页面:
randomPuppy(subreddit)
从所选子Reddit返回
promise
,以获取随机图像URL。警告:我们不能保证它将成为小狗的照片!
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);
});