-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
55 lines (43 loc) · 1.62 KB
/
bot.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import discord
import asyncio
from gtts import gTTS
client = discord.Client()
@client.event
async def on_ready():
print("Bot online")
@client.event
async def on_message(message):
if message.content.startswith('!TTV') or message.content.startswith('!ttv') or message.content.startswith('!say'):
text = message.content[5:]
tts = gTTS(text=text, lang='en')
tts.save('TTV.mp3')
channel = client.get_channel('INSERT YOUR VOICE CHANNEL HERE')
vc = await client.join_voice_channel(channel)
player = vc.create_ffmpeg_player('TTV.mp3')
player.start()
while player.is_playing():
async for message in client.logs_from(channel, limit=1):
if message.content.startswith('!stop'):
break
i = 0
while i == 0:
try:
for x in client.voice_clients:
await x.disconnect()
i = 1
except:
i = 1
continue
elif message.content.startswith('!stop'):
i = 0
while i == 0:
try:
for x in client.voice_clients:
await x.disconnect()
i = 1
except:
i = 1
continue
elif message.content.startswith('!help'):
await client.send_message(message.channel, 'Hello, please type !say followed by a space and then the text you would like the bot to say in your main voice channel! Type !stop to stop the bot during text to speech')
client.run('INSERT YOUR BOT KEY HERE')