forked from staciax/valorant-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
73 lines (58 loc) · 1.84 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Standard
import os
import asyncio
import aiohttp
import discord
from dotenv import load_dotenv
from discord.ext import commands
# Local
from utils.valorant.db import DATABASE
from utils.valorant.endpoint import API_ENDPOINT
from utils.valorant.cache import get_cache
load_dotenv()
initial_extensions = [
'cogs.error_handler',
'cogs.admin',
'cogs.notify',
'cogs.valorant'
]
# intents required
intents = discord.Intents.default()
intents.message_content = True
class ValorantBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix='-', case_insensitive=True, intents=intents)
owner_id = os.getenv('OWNER_ID')
if owner_id is not None:
try:
self.owner_id = int(owner_id)
except ValueError:
pass
self.bot_version = '3.0.5'
async def load_cogs(self) -> None:
for ext in initial_extensions:
await self.load_extension(ext)
def setup_cache(self) -> None:
try:
open('data/cache.json')
except FileNotFoundError:
get_cache()
async def setup_hook(self) -> None:
self.session = aiohttp.ClientSession()
self.db = DATABASE()
self.endpoint = API_ENDPOINT(self.session)
self.setup_cache()
await self.load_cogs()
async def close(self) -> None:
await self.session.close()
async def on_ready(self) -> None:
await self.tree.sync()
print(f"\nLogged in as: {self.user}\n\n BOT IS READY !")
print(f"Version: {self.bot_version}")
async def start(self) -> None:
return await super().start(os.getenv('TOKEN'), reconnect=True)
def run_bot():
bot = ValorantBot()
asyncio.run(bot.start())
if __name__ == '__main__':
run_bot()