我正在为我的discord bot构建一个serverinfo
斜杠命令,但是我遇到了这个错误,这可能是由于我的代码的.addFields
部分。以下是我在测试命令时得到的错误:
CombinedPropertyError (5)
Received one or more errors
input[1]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | 16
input[2]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | 1
input[3]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | 5
input[4]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | 2
input[5]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | 2
at ArrayValidator.handle (/home/runner/tester/node_modules/@sapphire/shapeshift/dist/index.js:468:70)
at ArrayValidator.parse (/home/runner/tester/node_modules/@sapphire/shapeshift/dist/index.js:207:88)
at EmbedBuilder.addFields (/home/runner/tester/node_modules/@discordjs/builders/dist/index.js:222:31)
at Object.execute (/home/runner/tester/commands/info/serverinfo.js:21:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
我不知道这会是什么。下面是我写的代码:
const {
SlashCommandBuilder,
EmbedBuilder
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("serverinfo")
.setDescription("Provides information about the server.")
.setDMPermission(false),
async execute(client, interaction) {
const { guild } = interaction;
const { members, channels, emojis, roles, stickers } = guild;
const embed = new EmbedBuilder()
.setColor("#2B2D31")
.setTitle(`${guild.name} - Server info`)
.setThumbnail(guild.iconURL({ size: 256 }))
.setImage(guild.bannerURL({ size: 256 }))
.addFields(
{ name: "Owner", value: (await guild.fetchOwner()).user.tag, inline: true },
{ name: "Text Channels", value: guild.channels.cache.filter((c) => c.type === 0).toJSON().length, inline: true },
{ name: "Voice Channels", value: guild.channels.cache.filter((c) => c.type === 2).toJSON().length, inline: true },
{ name: "Category Channels", value: guild.channels.cache.filter((c) => c.type === 4).toJSON().length, inline: true },
{ name: "Members", value: guild.memberCount, inline: true },
{ name: "Roles", value: guild.roles.cache.size, inline: true },
{ name: "Role List", value: guild.roles.cache.toJSON().join(', ')},
);
interaction.reply({ embeds: [embed] });
},
};
有什么想法吗?先谢了
2条答案
按热度按时间ef1yzkbh1#
这个错误很简单。字段值应该是字符串原语,但您提供数字。所有这些
.length
属性,guild.memberCount
和cache.size
都是数字。要解决这个问题,您需要将它们转换为字符串。此外,您不需要使用
toJSON()
,因为filter()
返回一个集合,您可以使用size
属性:如果你喜欢的话,你也可以这样使用模板文字:
gstyhher2#
.addFields
方法使用一个对象数组。你可能忘了你的方括号。只需将它们添加到以下位置:这里是固定的:
最简单的错误往往是我们犯的错误。
如果这个问题没有解决,请在下面发表评论。快乐编码!