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:
JavaScript
x
27
27
1
const { getAudioUrl } = require('google-tts-api')
2
3
let language = args[0]
4
5
if(!language) return message.reply("Please enter the language")
6
if(!text) return message.reply("Please enter the text")
7
const text = args.join(" ")
8
if(text.length > 200) return message.reply('You cant input a text with over 200 characters')
9
const voiceChannel = message.member.voice.channel
10
if(!voiceChannel) return message.reply(" Please enter a voice channel")
11
12
const audioURL = await getAudioUrl(text, {
13
lang: language,
14
slow: false,
15
host: 'https://translate.google.com',
16
timeout: '150000'
17
})
18
19
try {
20
voiceChannel.join().then(connection => {
21
const dispatcher = connection.play(audioURL)
22
dispatcher.on('finish', () => {
23
voiceChannel.leave()
24
})
25
})
26
}
27
Advertisement
Answer
You will need to remove the first item ("en"
) from your args
array and join
the rest:
JavaScript
1
4
1
const text = args.slice(1).join(" ")
2
3
if(!text) return message.reply("Please enter the text")
4