This repository was archived by the owner on Dec 21, 2024. It is now read-only.
forked from SylvesterFox/GrechkaBOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (53 loc) · 2.27 KB
/
main.py
File metadata and controls
65 lines (53 loc) · 2.27 KB
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
import discord
import logging
from random import choice
from discord.ext import commands, tasks
from database import init_bot_db, RolesDatabase
from settings_bot import config
role_db = RolesDatabase()
settings = config()
class DiscordClient(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
self.log = logging.getLogger('LunaBot')
super().__init__(
command_prefix=settings["prefix"],
intents=intents)
@tasks.loop(seconds=60.0)
async def status(self):
status = settings['game_activity']
random_activity = choice(status)
match random_activity['activity']:
case "game":
await self.change_presence(activity=discord.Game(name=random_activity['name']))
case "listening":
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening,
name=random_activity['name']))
case "watching":
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.watching,
name=random_activity['name']))
async def setup_hook(self):
for extend in settings['extension']:
await self.load_extension(extend)
self.log.info(f"Load - {extend}")
await self.tree.sync(guild = discord.Object(id = settings["main_guild"]))
# await self.tree.sync(guild=discord.Object(id=617020672929169418)) # это для дебага
self.log.info(f"Synced slash commands for {self.user}")
async def setup_emoji(self):
channel_db = role_db.db_channel_id()
if len(channel_db) == 0:
return
for row in channel_db:
channel = self.get_channel(row[0])
message = await channel.fetch_message(row[1])
await message.add_reaction(row[2])
async def on_ready(self):
init_bot_db()
print(f"Буп!\nВы вошли как {self.user}")
self.status.start()
try:
await self.setup_emoji()
except Exception as e:
self.log.error(e)
client = DiscordClient()