node.js - 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')
解决方案
如果你只发送一个字符串,你可以使用message.channel.send('TEXT')
. 对于嵌入,属于.send()
函数的“选项”参数;因此,您必须将其作为对象发送。换句话说,使用message.channel.send({ embed: embed })
.
推荐阅读
- node.js - Nodejs Mongodb:findByIdAndUpdate 没有返回正确的错误
- python - 一个漂亮的 pystan 轨迹图,用于 stan 矢量参数
- ios - 按钮单击不适用于自定义 UIView
- rest - 如何在 heroku 中找到 process.env.PORT 端口号?
- javascript - Chart.js - 如何在折线图的 X 轴上制作比例间隔
- javascript - 如何对 TweenMax 进行单元测试?潜在的模拟?
- c# - ASp.net Webform 多行文本框在页面加载时自动添加换行符
- java - 如何使用 java 8 在 HashMaps 列表上进行多重聚合
- javascript - 如何隐藏 Blueprint.js 开关组件周围的边框?
- r - R-通过根据条件删除重复项来创建数据集 - 过滤器