英文:
Trying to create a function that creates a discord Embed but am coming up with no luck
问题
我正在尝试创建一个函数,该函数创建一个 DiscordJS 嵌入,然后返回它以便发送,但是我遇到了一个大问题。以下是我收到的错误片段:
ValidationError:预期值是一个对象,但实际收到的是字符串
验证器:'s.object(T)',
给定:'Moon Wolf'
以下是代码的一部分:
function createEmbed(color,username,userURL,message) {
let Discord = require('discord.js');
let nullEmbed = new Discord.MessageEmbed()
.setColor(`#${color}`)
.setAuthor(username.username)
.setThumbnail(userURL)
.setDescription(`${message}`);
return nullEmbed;
}
那么我是否能在函数中这样做,还是我必须在每个块中手动执行?
注意:username
是 message.author
对象,userURL
是用户的图像 URL。
英文:
So I'm trying to create a function that creates a discordjs embed, then returns it so it can be sent, however, I'm being met with a big problem. Here is a snipped of the error I got
ValidationError: Expected the value to be an object, but received string instead
validator: 's.object(T)', given: 'Moon Wolf' }
So heres a snippet of the code
let Discord = require('discord.js');
let nullEmbed = new Discord.EmbedBuilder()
.setColor(`#${color}`)
.setAuthor(username.username)
.setThumbnail(userURL)
.setDescription(`${message}`);
return nullEmbed;
}
So am I even able to do this in a function or would I have to do it manually throughout each block?
Note: username is the object message.author and the userURL is the users image url
答案1
得分: 0
在setAuthor
内部需要是一个对象,而不是一个字符串
示例:
.setAuthor({ name: username.username })
英文:
Inside setAuthor
needs to be an object and not a string
Example:
.setAuthor({ name: username.username })
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论