初始前提:我从来没有使用过布尔值,我是一个初学者
代码:
const {
SlashCommandBuilder,
PermissionFlagsBits,
PermissionsBitField,
EmbedBuilder,
} = require("discord.js");
const { generateDependencyReport, AudioPlayerStatus, joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const googleTTS = require("google-tts-api");
const translate = require("google-translate-api-x");
module.exports = {
data: new SlashCommandBuilder()
.setName(`tts`)
.setDescription(`Fai ripetere al bot un messaggio in un canale vocale`)
.addStringOption((option) =>
option
.setName("messaggio")
.setDescription("Scrivi il messaggio da far ripetere dal bot in vocale")
.setRequired(true)
)
.addBooleanOption((option) =>
option
.setName("rallentatore")
.setDescription("Vuoi che il messaggio sia mandato a rallentatore?")
.setRequired("true")
),
async execute(interaction, client) {
const testo = interaction.options.getString("messaggio");
const slow = interaction.options.getBoolean("rallentatore");
const res = await translate(`${testo}`, {to: aa});
const url = googleTTS.getAudioUrl(testo, {
lang: res.from.language.iso,
slow: slow,
host: 'https://translate.google.com',
});
const { generateDependencyReport, AudioPlayerStatus, joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const voiceChannelId = interaction.member.voice.channel.id
const voiceChannel = interaction.member.voice.channel
const guildId = interaction.guild.id
const player = createAudioPlayer();
const resource = createAudioResource(url);
player.play(resource);
const connection = joinVoiceChannel({
channelId: voiceChannelId,
guildId: guildId,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});
const subscription = connection.subscribe(player);
if (subscription) {
setTimeout(() => subscription.unsubscribe(), 30_000);
}
},
};
错误:
ValidationError: Expected a boolean primitive
at BooleanValidator.handle (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\node_modules\@sapphire\shapeshift\dist\index.js:552:71)
at BooleanValidator.parse (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at validateRequired (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\node_modules\@discordjs\builders\dist\index.js:849:20)
at SlashCommandBooleanOption.setRequired (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\node_modules\@discordjs\builders\dist\index.js:962:5)
at C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\src\commands\tools\tts.js:26:8
at MixedClass._sharedAddOptionMethod (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\node_modules\@discordjs\builders\dist\index.js:1262:50)
at MixedClass.addBooleanOption (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\node_modules\@discordjs\builders\dist\index.js:1233:17)
at Object.<anonymous> (C:\Users\Casa\OneDrive\Desktop\Discord\eKicks\eKicks Bot v14\src\commands\tools\tts.js:22:6)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10) {
validator: 's.boolean',
given: 'true'
我已经尝试了所有的方法来修复它。正如我上面所说的,我不是一个有技能或知识的开发人员,但我是一个初学者,如果这个问题可能很明显或简单,我道歉。这是我第一次使用布尔值,所以我不知道如何去做
1条答案
按热度按时间f0brbegy1#
欢迎光临!
尝试在
SlashCommandBuilder
中将.setRequired("true")
更改为.setRequired(true)
,应该可以解决问题。您发送的是**“字符串”而不是实际的布尔值**。