javascript - 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);
}
});
解决方案
你误用了这个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.*
`)
我希望我已经回答了您的所有问题,这将帮助您解决问题!:)
推荐阅读
- php - 在 php 表中显示不同的级别
- logging - 你可以在godot中制作一个日志文件吗?
- java - 如何在 Shiro SessionListener 中触发会话到期重定向?
- unit-testing - Azure Devops 是否有与 tcm / import 类似的工具?
- scala - Scala应用无法返回选项
- python - 在 python 中,如何创建一个列表列表,其中每个列表都包含一个开始和结束日期的字符串表示形式?
- java - HttpsURLConnection POST 方法失败。我不知道我是否有正确的编写器和/或输出流编写器。对于多部分/表单数据
- postgresql - NpgSQL 奇怪的行为
- react-native - 如何从 firebase crashlytics 堆栈跟踪文本 index.android.bundle 或 iOS main.jsbundle 获取错误源文件?
- docker - 如何在 docker 容器中安装 nftables 及其依赖项?