-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (49 loc) · 1.4 KB
/
main.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
56
57
import sys, os
import pyttsx3
import discord
from discord import Intents
import asyncio
from discord.ext import commands
from discord import FFmpegPCMAudio
from discord.utils import get
intents = Intents.all()
bot = commands.Bot(intents = intents, command_prefix = '^')
engine = pyttsx3.init()
loop = asyncio.get_event_loop()
print(loop)
self = discord.User
if 'TOKEN' not in os.environ:
print('No bot token (TOKEN) in the list of environment variables')
exit()
token = os.environ['TOKEN']
@bot.event
async def on_ready():
print('Logged on as', self)
await bot.change_presence(
activity = discord.Activity(
type = discord.ActivityType.listening,
name = 'Markov'))
@bot.listen('on_message')
async def tts(ctx):
messageContent = ctx.content
if ctx.author.bot == True:
print(messageContent)
engine.save_to_file(messageContent, 'filler.mp3')
engine.runAndWait()
voice = get(bot.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('filler.mp3')
player = voice.play(source)
else:
return
@bot.command(pass_context=True)
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
@bot.command(pass_context=True)
async def leave(ctx):
await ctx.voice_client.disconnect()
@bot.command(pass_context=True)
async def test(ctx):
await ctx.send('This is a test message!', tts=True)
if loop.is_running() == False:
bot.run(token)