-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (40 loc) · 1.08 KB
/
app.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
#!/usr/bin/env python3
import os
import discord
from discord.utils import oauth_url
from discord.ext import commands, tasks
from discord.ext.commands import CommandNotFound
from dotenv import load_dotenv
from plugins import tts
load_dotenv()
intents = discord.Intents().all()
client = discord.Client(intents=intents)
bot = commands.Bot(
command_prefix="'",
intents=intents
)
bot.add_cog(tts.TTS(bot))
# https://stackoverflow.com/a/52900437
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, CommandNotFound):
return
raise error
async def bot_leave_voices(bot):
for vc in bot.voice_clients:
await vc.disconnect()
if __name__ == '__main__':
print(
"Invite:",
oauth_url(
os.getenv('DISCORD_CLIENT_ID'),
permissions=discord.Permissions(int(os.getenv('DISCORD_PERMISSIONS'))),
)
)
try:
bot.loop.run_until_complete(bot.start(os.getenv('DISCORD_CLIENT_TOKEN'), bot=True))
except KeyboardInterrupt:
bot.loop.run_until_complete(bot_leave_voices(bot))
bot.loop.run_until_complete(bot.logout())
finally:
bot.loop.close()