-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (51 loc) · 1.92 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
58
59
60
61
62
63
64
import discord
from discord.ext import commands
import asyncio
import logging
from dotenv import load_dotenv
import os
import aiohttp
load_dotenv()
token = os.getenv('DISCORD_BOT_TOKEN')
tenor_api_key = os.getenv('TENOR_TOKEN')
class Client(commands.Bot):
def __init__(self):
super().__init__(command_prefix="?", intents=discord.Intents().all())
self.coglist = ["cogs.commands", "cogs.appreciation", "cogs.random_gif", "cogs.task_reminder", "cogs.pikmin"]
self.logger = logging.getLogger("logger")
self.logger.addHandler(logging.FileHandler("logger.log"))
self.logger.setLevel(logging.DEBUG)
self.session = None
self.tenor_api_key = tenor_api_key
async def on_ready(self):
try:
print(f"Successfully logged in as {self.user}!")
synced = await self.tree.sync()
print(f"Synced {len(synced)} commands!")
syn = await self.tree.sync(guild=discord.Object(id="ID Here"))
print(f'Synced {len(syn)} in {syn[0].guild.name}' if syn else 'No commands were synced')
except Exception as err:
self.logger.error(err)
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="to help"))
async def setup_hook(self):
self.session = aiohttp.ClientSession()
for ext in self.coglist:
await self.load_extension(ext)
await self.tree.sync()
async def close(self):
await super().close()
if self.session:
await self.session.close()
client = Client()
logging.basicConfig(filename="log.txt", level=logging.INFO)
async def main():
async with client:
try:
await client.start(token)
except Exception as err:
client.logger.error(err)
finally:
if not client.is_closed():
await client.close()
if __name__ == "__main__":
asyncio.run(main())