javascript - Discord.js ReferenceError:尝试测试嵌入时未定义通道
问题描述
我正在开发一个不和谐的机器人,我试图测试一个嵌入并且弹出一个错误说
ReferenceError:未定义通道
这是嵌入的代码
client.on('message', (message) => {
console.log(`[${message.author.tag}]: ${message.content}`);
if (message.content === 'brh!testembed') {
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
channel.send(exampleEmbed);
}
});
解决方案
就像错误说你没有定义channel
如果你想将嵌入发送到与你的命令使用相同的频道只是做:
message.channel.send(exampleEmbed);
如果您使用的是v13 ,请使用:
message.channel.send({embeds: [exampleEmbed]});
推荐阅读
- python - 在 python 中求解时空偏微分方程
- tensorflow - 如何从 pandas 创建与 tf.data.experimental.make_csv_dataset 相同的结构
- javascript - 脚本内的异步等待 - 使用 fetch 的 API 调用不返回结果
- javascript - express passport nginx 代理不适用于旧版浏览器
- jetbrains-ide - 哪些设置保存在 .idea 文件夹下,哪些不保存?
- javascript - 在使用箭头函数时,作为回调的函数会在不考虑事件侦听器的情况下重新加载,从而提供预期的行为。为什么会这样?
- python - cron中的python脚本
- jquery-plugins - Livewire Dom 更新中断 jquery 插件,如 Select2 .. 等
- react-native - 如何在本机反应中解决图像加载问题
- laravel - 有没有办法在 laravel、flutter 或 dart 中按计划日期或时间自动分配数据?