【发布时间】:2021-09-04 05:30:48
【问题描述】:
我目前正在使用 node.js 制作一个不和谐的机器人,但我在执行 kick 和 ban 命令时发现了一个问题。我试图确保嵌入不和谐,但我一直遇到这个问题。 有人可以帮我吗?
这是一个嵌入代码:
const kickembed = new Discord.MessageEmbed()
.setTitle('Member Kicked')
.setThumbnail(member.user.displayAvatarURL())
.addField('User Kicked', member)
.addField('Kicked by', message.author)
.addField('Reason', reason)
.setFooter('Time Kicked', client.user.displayAvatarURL())
.setTimestamp()
message.channel.send(kickembed);
这是一个错误日志:
(node:2400) UnhandledPromiseRejectionWarning: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty.
at Function.normalizeField (D:\DATA\Discord Bot\Tutorial #2\node_modules\discord.js\src\structures\MessageEmbed.js:432:23)
at D:\DATA\Discord Bot\Tutorial #2\node_modules\discord.js\src\structures\MessageEmbed.js:452:14
at Array.map (<anonymous>)
at Function.normalizeFields (D:\DATA\Discord Bot\Tutorial #2\node_modules\discord.js\src\structures\MessageEmbed.js:451:8)
at MessageEmbed.addFields (D:\DATA\Discord Bot\Tutorial #2\node_modules\discord.js\src\structures\MessageEmbed.js:266:42)
at MessageEmbed.addField (D:\DATA\Discord Bot\Tutorial #2\node_modules\discord.js\src\structures\MessageEmbed.js:257:17)
at Object.run (D:\DATA\Discord Bot\Tutorial #2\commands\kick.js:35:6)
at Client.<anonymous> (D:\DATA\Discord Bot\Tutorial #2\index.js:51:40)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
ated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
【问题讨论】:
-
您的自定义字段中的某个人似乎收到了一个空值。确保您的所有 addField 调用都传递了一个有效值(应该是一个不为空的字符串)。这是 normalizeField github.com/discordjs/discord.js/blob/… 调用的函数
-
下次提出问题时,如果您显示
message和member的定义位置,对尝试解决您的问题的人会更有用。
标签: javascript node.js npm discord.js