首页 > 解决方案 > Discord.js“未定义”。如何删除我的嵌入命令中的未定义?

问题描述

我使用了下面的代码,得到了这个结果。我不知道如何删除“未定义”您可以为我提供更好的代码或修改我的代码吗?

在此处输入图像描述

client.on('message', message => {
  if (message.content === '?welcomemsg') {
    const MessageEmbed = new Discord.MessageEmbed()
      .setColor('#FF0000')
      .addField(`*Welcome to PhyZics Public Discord! We created this server so in order for us to stay connected to our grinders and our to our community members.*`)
      .addField('\u200b')
      .addField(`*PhyZics is a community and team created to recongnize small players and grinders that have the potential to play for our team.*`)
      .setFooter('PhyZics Management Team; PhyZics Bot powered by Jun');
    message.channel.send(MessageEmbed);
  }
});

标签: javascriptdiscorddiscord.js

解决方案


你误用了这个addField方法。
根据文档,您需要在所有字段中添加标题和描述,如下所示:

MessageEmbed.addField('Your cool title', 'An even cooler description !')

看到您的代码后,我认为setDescription方法对于您想要实现的目标会更好。
这将使您的最终嵌入看起来像这样:

const MessageEmbed = new Discord.MessageEmbed()
      .setColor('#FF0000')
      .setDescription(`*Welcome to PhyZics Public Discord! We created this server so in order for us to stay connected to our grinders and our to our community members.* \n*PhyZics is a community and team created to recognize small players and grinders that have the potential to play for our team.*`)
      .setFooter('PhyZics Management Team; PhyZics Bot powered by Jun');
message.channel.send(MessageEmbed);

请注意\n字符的用法,这会在您的描述中创建一个换行符。
执行以下操作将导致完全相同的结果:

setDescription(`
*Welcome to PhyZics Public Discord! We created this server so in order for us to stay connected to our grinders and our to our community members.*
*PhyZics is a community and team created to recognize small players and grinders that have the potential to play for our team.*
`)

我希望我已经回答了您的所有问题,这将帮助您解决问题!:)


推荐阅读