discord.js 机器人在尝试发送嵌入时报告 [object object]
Posted
技术标签:
【中文标题】discord.js 机器人在尝试发送嵌入时报告 [object object]【英文标题】:discord.js bot reports [object object] when trying to send an embed 【发布时间】:2020-06-29 01:43:06 【问题描述】:我正在编写一个必须发送嵌入的机器人。但是当发送嵌入时,机器人会说[object Object]
。
嵌入代码:
const embed9 = new Discord.MessageEmbed()
.setTitle("1h Until Convoy - Sim1")
.setURL("https://www.scanialtd.com/")
.setColor(16571139)
.setDescription("There is 1 hour untill the convoy on Simulation 1 in ETS2. Get ready to join by launching ETS2 and logging on to Simulation 1. Join the Convoy Lounge while you wait.")
.setFooter("Created by ScaniaLTD Convoy Announcements Bot, https://www.scanialtd.com/uploads/6/3/4/9/63493649/published/logo_3.png")
.setImage("http://i.imgur.com/yVpymuV.png")
.setThumbnail("https://www.scanialtd.com/uploads/6/3/4/9/63493649/published/logo_3.png")
.setTimestamp()
message.channel.send('@ConvoyReminders' + embed9)
【问题讨论】:
简化标题和问题 【参考方案1】:您正在连接一个字符串和一个内部带有 embed9 的对象。
要提及某人,您需要在.setDescription
中添加@<Username>
。那你就可以message.channel.send(embed9)
【讨论】:
【参考方案2】:因为您尝试在 1 个参数中发送搅拌 + 嵌入对象。
你不能用他们的name + @
来提及他们,你需要使用user.id
来表示这个,比如<@213123131321>
或<@&1232312123132>
来表示角色。
正确的方式:
const embed9 = new Discord.MessageEmbed()
.setTitle("1h Until Convoy - Sim1")
.setURL("https://www.scanialtd.com/")
.setColor(16571139)
.setDescription("There is 1 hour untill the convoy on Simulation 1 in ETS2. Get ready to join by launching ETS2 and logging on to Simulation 1. Join the Convoy Lounge while you wait.")
.setFooter("Created by ScaniaLTD Convoy Announcements Bot, https://www.scanialtd.com/uploads/6/3/4/9/63493649/published/logo_3.png")
.setImage("http://i.imgur.com/yVpymuV.png")
.setThumbnail("https://www.scanialtd.com/uploads/6/3/4/9/63493649/published/logo_3.png")
.setTimestamp()
message.channel.send('@ConvoyReminders', embed9)
【讨论】:
以上是关于discord.js 机器人在尝试发送嵌入时报告 [object object]的主要内容,如果未能解决你的问题,请参考以下文章
Discord.js 分片,如何使用 broadcastEval 发送嵌入消息?