首页 > 解决方案 > Discord.js ReferenceError:嵌入未定义

问题描述

我是编码新手,所以我决定制作一个从 Reddit 发送模因的不和谐机器人。但是每当我发送命令时,它都会给我错误并使机器人崩溃。我做错了什么,我该如何解决

这是所有不和谐机器人

const Discord = require('discord.js');
const client = new Discord.Client();
const randomPuppy = require('random-puppy');
const prefix = '%'

client.once('ready', () => {
    console.log('CounterOutplayer is READY!');
});

module.exports = {
    name: "meme",
    description: "Random image from a specific subreddit",
    async run (client, message, args){
        const subReddits = ["memes", "dankmemes"]
        const random = subReddits[Math.floor(Math.random() * subReddits.length)]

        const img = await randomPuppy(random);

        const embed = new Discord.MessageEmbed()
        .setColor("Green")
        .setImage(img)
        .setTitle(`memes - ${random}`)
        .setURL(`https://reddit.com/r/${random}`)

        message.channel.send(embed);
    }
}


client.login('token')

标签: node.jsdiscorddiscord.js

解决方案


如果你只发送一个字符串,你可以使用message.channel.send('TEXT'). 对于嵌入,属于.send()函数的“选项”参数;因此,您必须将其作为对象发送。换句话说,使用message.channel.send({ embed: embed }).


推荐阅读