JavaScript Discord Embed bess not读取某些嵌入。集合命令。 (Discord Meme Bot)

发布于 2025-02-04 02:08:49 字数 1423 浏览 4 评论 0原文

我正在尝试制作一个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;
code screenshot

But when I use the command in discord, the reply only shows the description, not the color or image.

discord screenshot

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画离情绘悲伤 2025-02-11 02:08:49

方法 randompuppy()是异步的。这意味着您需要等待承诺发送嵌入消息。在当前的代码中,您在不等待完成请求的情况下发送嵌入。

您必须从

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
});

message.channel.send(cuteEmbed);

以下方式更改代码:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
  message.channel.send(cuteEmbed); //Send the embed once the request is completed.
});

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:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
});

message.channel.send(cuteEmbed);

To:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
  message.channel.send(cuteEmbed); //Send the embed once the request is completed.
});
靖瑶 2025-02-11 02:08:49
    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        });

        message.channel.send(cuteEmbed);
    }

您正在尝试发送嵌入的嵌入,即使请求尚未完成,您需要做的就是将message.Channel.Send()放入的内部。

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        message.channel.send(cuteEmbed);
        });
    }

然后注意到您错过的内容键入键>键>您应该键入BackQuote而不是Quote,因此在编辑代码后。您只需要将Quote编辑为BackQuote

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}'); //This is the part you need to change it
        message.channel.send(cuteEmbed);
        });
    }

对此:

   randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url; //image should call this after changing it
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage(`${cuteurl}`); //To this, to call your cuteurl
        message.channel.send(cuteEmbed);
        });
    }
    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        });

        message.channel.send(cuteEmbed);
    }

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

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        message.channel.send(cuteEmbed);
        });
    }

And I noticed something that you missed type one of the keypress you should type backquote instead of quote, so after editing your code. You just need to edit the quote to backquote:

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}'); //This is the part you need to change it
        message.channel.send(cuteEmbed);
        });
    }

To this:

   randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url; //image should call this after changing it
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage(`${cuteurl}`); //To this, to call your cuteurl
        message.channel.send(cuteEmbed);
        });
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文