-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 1.59 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Discord = require("discord.js");
const client = new Discord.Client();
const googleTTS = require('google-tts-api');
require('dotenv').config()
const prefix = "_speak";
const prefix1 = "!speak";
// if (client.channels.id === "739587032791121941") {
// }
client.on("message", async (msg) => {
// console.error(msg)
if (msg.content.startsWith(prefix + "help") || msg.content.startsWith(prefix1 + "help")) {
msg.reply("\nCommand:\n\t_speak[lang] <message>\n\t!speak[lang] <message>\nExample:\n\t_speakit ciao\n\t!speaken hello\nLanguage codes:\n\tENGLISH: en\n\tITALIANO: it\n\tBANGLA: bn\nPer la lista completa visitare https://cloud.google.com/text-to-speech/docs/voices")
} else if (msg.content.startsWith(prefix) || msg.content.startsWith(prefix1)) {
if (msg.member.voice.channel) {
const playable = await msg.member.voice.channel.join();
googleTTS(`${msg.content.slice(msg.content.indexOf(" "))}`, `${msg.content.slice(6, msg.content.indexOf(" "))}`, 1) // speed normal = 1 (default), slow = 0.24
.then(function (url) {
// console.log(url); // https://translate.google.com/translate_tts?...
const dispatcher = playable.play(url);
})
.catch(function (err) {
console.error(err.stack);
});
} else {
message.reply('You need to join a voice channel first!');
}
}
})
client.on("ready", () => {
console.log("bot is connected")
})
client.login(`${process.env.BOT_TOKEN}`);