我如何读取另一个机器人嵌入的作者字段?

时间:2021-03-29 09:17:25

标签: discord discord.js

编辑:

我想通了,你可以找到另一个机器人嵌入的作者字段

message.embeds[0].author.name

原始问题:

To be clear about 'author', this is the 'author' I'm mentioning.

我已经写了一个正则表达式来检测嵌入的作者是否包含 [username] 搜索了 [place]:

const matches = message.embeds[0].author.match(new RegExp("\\*\\*<@!?\\d{1,}> searched the:\\*\\*"));

但是有一个错误:

TypeError: cannot read property 'author' of undefined

希望得到一些帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

正如错误消息所暗示的,undefined 没有属性 author。这意味着 embeds[0] 未定义。发送的消息很可能没有嵌入,因此如果没有嵌入,您应该将该行放在 if(typeof message.embeds[0] !== 'undefined') { 中以停止代码运行。