尝试创建一个能够创建Discord嵌入消息的函数,但一直没有成功。

huangapple go评论68阅读模式
英文:

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;
}

那么我是否能在函数中这样做,还是我必须在每个块中手动执行?

注意:usernamemessage.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 })

huangapple
  • 本文由 发表于 2023年1月10日 06:22:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75063566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定