【发布时间】:2021-09-24 19:30:40
【问题描述】:
我正在尝试根据给定的 JSON 数据创建一个发送嵌入的命令,它确实有效。
我给机器人提供数据,如果它是正确的,它会将它发送到频道,这很完美,正是我需要它做的。但是,如果有人试图将文本放在链接部分,它会使机器人崩溃。我试过try catch,但由于某种原因它不会捕获。
错误:Scheme "(my string that is not a url)" is not supported. Scheme must be one of ('http', 'https').
try {
let json = message.content.split(" ")
json.shift() //get rid of the command bit, leaving the JSON
let data = json.join(" ")
let embedjson = new Discord.MessageEmbed(JSON.parse(data))
message.channel.send({ embeds: [embedjson]}) //this works, unless it meets the problem listed above.
} catch (error) { // >:( wont catch it
let errorembed = new Discord.MessageEmbed()
console.log(error)
.setTitle('Error!')
.setDescription(`Something went wrong! There are a few possible issues:\n1. You tried to put text in a link option (Like putting 'hello' in the image option, or 'never gonna give you up' in the thumbnail option.)\n2. Something else\nI'll attatch the error below:`)
.addField('Error Message', error)
message.channel.send({ embeds: [errorembed]})
}
关于如何发现错误有什么建议吗?非常感谢任何帮助。
【问题讨论】:
-
我相信添加
async-await有效。测试它并告诉我会发生什么。 -
@MrMythical 好的,我将
execute()更改为async execute()并执行await message.channel.send()并再次运行它,但没有成功。接下来我将尝试 danky 的解决方案。
标签: javascript node.js discord discord.js