向 Slash 命令添加角色选项时出错 ~ @discordjs/builders
Error in adding role options to Slash Command ~ @discordjs/builders
我正在尝试为斜杠命令创建多个角色选项。我正在使用 Slash Command builder - @discordjs/builders
我尝试了不同的方法但没有用。这是我的代码:
data: new SlashCommandBuilder()
.setName('roles')
.setDescription('Choices')
.addRoleOption(role =>
role.setName('role 1').setDescription('Choice 1').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 2').setDescription('Choice 2').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 3').setDescription('Choice 3').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 4').setDescription('Choice 4').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 5').setDescription('Choice 5').setRequired(false)
),
我做这个的错误:
S[50035]: Invalid Form Body
3.options[0].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[1].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[2].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[3].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[4].name[STRING_TYPE_REGEX]: String value did not match validation regex.
at Q.runRequest (/home/runner/ticket-1/node_modules/@discordjs/rest/dist/index.js:7:581)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Q.queueRequest (/home/runner/ticket-1/node_modules/@discordjs/rest/dist/index.js:5:2942)
at async /home/runner/ticket-1/handler/slashCommand.js:35:9 {
rawError: {
code: 50035,
errors: { '3': [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'put',
url: 'https://discord.com/api/v9/applications/935368903209672726/guilds/908385923673231481/commands',
requestBody: {
files: undefined,
json: [ [Object], [Object], [Object], [Object] ]
}
}
请帮我解决这个问题。
我现在发现了问题:您不能在选项名称的字符之间包含 space
。
因此,代码为:
.addRoleOption(role =>
role.setName('role1').setDescription('Select role').setRequired(false)
)
我希望这对遇到同样问题的其他人有所帮助。
我正在尝试为斜杠命令创建多个角色选项。我正在使用 Slash Command builder - @discordjs/builders
我尝试了不同的方法但没有用。这是我的代码:
data: new SlashCommandBuilder()
.setName('roles')
.setDescription('Choices')
.addRoleOption(role =>
role.setName('role 1').setDescription('Choice 1').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 2').setDescription('Choice 2').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 3').setDescription('Choice 3').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 4').setDescription('Choice 4').setRequired(false)
)
.addRoleOption(role =>
role.setName('role 5').setDescription('Choice 5').setRequired(false)
),
我做这个的错误:
S[50035]: Invalid Form Body
3.options[0].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[1].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[2].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[3].name[STRING_TYPE_REGEX]: String value did not match validation regex.
3.options[4].name[STRING_TYPE_REGEX]: String value did not match validation regex.
at Q.runRequest (/home/runner/ticket-1/node_modules/@discordjs/rest/dist/index.js:7:581)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Q.queueRequest (/home/runner/ticket-1/node_modules/@discordjs/rest/dist/index.js:5:2942)
at async /home/runner/ticket-1/handler/slashCommand.js:35:9 {
rawError: {
code: 50035,
errors: { '3': [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'put',
url: 'https://discord.com/api/v9/applications/935368903209672726/guilds/908385923673231481/commands',
requestBody: {
files: undefined,
json: [ [Object], [Object], [Object], [Object] ]
}
}
请帮我解决这个问题。
我现在发现了问题:您不能在选项名称的字符之间包含 space
。
因此,代码为:
.addRoleOption(role =>
role.setName('role1').setDescription('Select role').setRequired(false)
)
我希望这对遇到同样问题的其他人有所帮助。