Trying to make a tts join command, getting invalid string format error

I'm currently trying to use a SlashCommandBuilder to make a command that will make the bot join the vc and begin reading messages, however I keep getting invalid string format when I try deploying the command
const { SlashCommandBuilder, ChannelType} = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, AudioPlayerStatus, VoiceConnection, getVoiceConnection, createAudioResource, createAudioPlayer, NoSubscriberBehavior} = require('@discordjs/voice')

module.exports = {
data: new SlashCommandBuilder()
.setName('TTSjoin')
.setDescription('Get discord bot to join the vc **WITH TTS**! (no leave command yet)')
.addChannelOption(option => option.setName('channel').setDescription('The channel to join').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {

const channel = interaction.options.getChannel('channel');

const OwnerID = '686407266408464391'

let connectionjoin = getVoiceConnection(interaction.guild.id);


if(connectionjoin != undefined && interaction.user.id === OwnerID) {
let leaveconnection = getVoiceConnection(interaction.guild.id);

leaveconnection.destroy();

const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});

const joinconnection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
await interaction.reply (`See you suckers, Box invited me to ${channel}!`)

voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);

const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});

if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}

joinconnection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
return;
}
else if(connectionjoin != undefined) {
await interaction.reply("I am in a vc!");
return;
}

const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);

const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});

if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}

connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
console.log(getVoiceConnection)

await interaction.reply(`Joined ${channel}!`);
},
};
const { SlashCommandBuilder, ChannelType} = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, AudioPlayerStatus, VoiceConnection, getVoiceConnection, createAudioResource, createAudioPlayer, NoSubscriberBehavior} = require('@discordjs/voice')

module.exports = {
data: new SlashCommandBuilder()
.setName('TTSjoin')
.setDescription('Get discord bot to join the vc **WITH TTS**! (no leave command yet)')
.addChannelOption(option => option.setName('channel').setDescription('The channel to join').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {

const channel = interaction.options.getChannel('channel');

const OwnerID = '686407266408464391'

let connectionjoin = getVoiceConnection(interaction.guild.id);


if(connectionjoin != undefined && interaction.user.id === OwnerID) {
let leaveconnection = getVoiceConnection(interaction.guild.id);

leaveconnection.destroy();

const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});

const joinconnection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
await interaction.reply (`See you suckers, Box invited me to ${channel}!`)

voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);

const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});

if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}

joinconnection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
return;
}
else if(connectionjoin != undefined) {
await interaction.reply("I am in a vc!");
return;
}

const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);

const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});

if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}

connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
console.log(getVoiceConnection)

await interaction.reply(`Joined ${channel}!`);
},
};
3 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Box Bunny with Fan Noises
node version: v18.16.0 discordjs version: [email protected]
six
six12mo ago
hey may i ask what tts package are you using
Want results from more Discord servers?
Add your server