首页 > 解决方案 > 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);
    
    }
});

标签: javascriptnode.jsdiscord.js

解决方案


就像错误说你没有定义channel如果你想将嵌入发送到与你的命令使用相同的频道只是做:

message.channel.send(exampleEmbed);

如果您使用的是v13 ,请使用:

message.channel.send({embeds: [exampleEmbed]});

推荐阅读