我在SlashCommandBuilder中有一个这样的选项:
.addStringOption((option) => option
.setName('city')
.setDescription('In which city are you currently based from?')
.addChoices(
{
name: 'City 1',
value: 'City-1-Example'
},
{
name: 'City 2',
value: 'City-2-Example'
}
)
.setRequired(true)
)
我正在考虑创建另一个单独的.js
文件,假设options.js
包含:
export const options = {
city: [
{
name: 'City 1',
value: 'City-1-Example'
},
{
name: 'City 2',
value: 'City-2-Example'
}
],
optionsForAnotherCommand: [
...
]
}
以便我可以轻松地在一个文件中编辑所有SlashCommandBuilder选项。使它整洁有序,我现在可以这样做:
.addStringOption((option) => option
.setName('city')
.setDescription('In which city are you currently based from?')
.addChoices(options.city)
.setRequired(true)
)
但是,它返回给我一个错误:
errors: [[ 0, ValidationError: Expected the value to not be an array ...
代码与第一个示例一起工作,但是如果我想更改所有命令的选项,因为我必须逐个文件打开它们,这将是一个麻烦。想知道如果这是可能的,或者如果它不是,是否有一个更有组织的方式来存储您的选项在一个SlashCommandBuilder?
谢谢你的回答@Zsolt Meszaros
答案很简单,你只要在它前面加上...
:
.addChoices(...options.city)