I’m trying to code discord tts bot but I run into a problem. When I used $speak en Hi guys
the bot said "en hi guys"
.
I tried making the bot not say the language code but I can’t so if you have any solution please share it with me.
Here is my code:
const { getAudioUrl } = require('google-tts-api') let language = args[0] if(!language) return message.reply("Please enter the language") if(!text) return message.reply("Please enter the text") const text = args.join(" ") if(text.length > 200) return message.reply('You cant input a text with over 200 characters') const voiceChannel = message.member.voice.channel if(!voiceChannel) return message.reply(" Please enter a voice channel") const audioURL = await getAudioUrl(text, { lang: language, slow: false, host: 'https://translate.google.com', timeout: '150000' }) try { voiceChannel.join().then(connection => { const dispatcher = connection.play(audioURL) dispatcher.on('finish', () => { voiceChannel.leave() }) }) }
Advertisement
Answer
You will need to remove the first item ("en"
) from your args
array and join
the rest:
const text = args.slice(1).join(" ") if(!text) return message.reply("Please enter the text")