JavaScript Discord Embed bess not读取某些嵌入。集合命令。 (Discord Meme Bot)
我正在尝试制作一个Discord Meme Bot(在这种情况下,可爱的动物图片机器人)。代码就是这样;
但是,当我在Discord中使用命令时,答复仅显示描述,而不是颜色或图像。
我在做什么错?
这是复制粘贴的命令文件的代码;
const { MessageEmbed } = require('discord.js');
const randomPuppy = require('random-puppy');
module.exports = {
name: 'cute',
description: 'Embeds pictures pulled from listed subreddits',
execute(message, args, Discord){
let reddit = [
"aww",
"puppies",
"toebeans"
]
let subreddit = reddit[Math.floor(Math.random()*reddit.length -1)];
const cuteEmbed = new MessageEmbed()
.setDescription("Some cute animals to blow away your anxieties!");
randomPuppy(subreddit).then(url => {
console.log(url);
const cuteurl = url;
cuteEmbed.setColor('#91B2C7');
cuteEmbed.setImage('${cuteurl}');
});
message.channel.send(cuteEmbed);
}
}
请帮助:'(
编辑:back ticks。
I'm trying to make a discord meme bot (in this case, cute animal pictures bot). The code is this;
But when I use the command in discord, the reply only shows the description, not the color or image.
What am I doing wrong?
here's the code of the command file for copy paste;
const { MessageEmbed } = require('discord.js');
const randomPuppy = require('random-puppy');
module.exports = {
name: 'cute',
description: 'Embeds pictures pulled from listed subreddits',
execute(message, args, Discord){
let reddit = [
"aww",
"puppies",
"toebeans"
]
let subreddit = reddit[Math.floor(Math.random()*reddit.length -1)];
const cuteEmbed = new MessageEmbed()
.setDescription("Some cute animals to blow away your anxieties!");
randomPuppy(subreddit).then(url => {
console.log(url);
const cuteurl = url;
cuteEmbed.setColor('#91B2C7');
cuteEmbed.setImage('${cuteurl}');
});
message.channel.send(cuteEmbed);
}
}
please help :'(
Edit: BACK TICKS. GODDAMN BACK TICKS. I'm using a new code so idk if using back ticks would've fixed it, but that's one mistake in the code; I didn't use backticks for interpolation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方法 randompuppy()是异步的。这意味着您需要等待承诺发送嵌入消息。在当前的代码中,您在不等待完成请求的情况下发送嵌入。
您必须从
以下方式更改代码:
The method randomPuppy() is asynchronous. Meaning that you need to wait for the promise to send the embed message. In your current code, you send the embed without waiting for the request to complete.
You have to change your code from:
To:
您正在尝试发送嵌入的嵌入,即使请求尚未完成,您需要做的就是将
message.Channel.Send()
放入的内部。
然后注意到您错过的内容键入
键>键>
您应该键入BackQuote
而不是Quote
,因此在编辑代码后。您只需要将Quote
编辑为BackQuote
:对此:
You are trying to send the embed even the request is not finished, all you need to do is to put the
message.channel.send()
inside of.then
And I noticed something that you missed type one of the
keypress
you should typebackquote
instead ofquote
, so after editing your code. You just need to edit thequote
tobackquote
:To this: