-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
executable file
·79 lines (62 loc) · 2.06 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
74
75
76
77
78
79
from nextcord import Activity, ActivityType, Intents
from nextcord.ext import commands
import os
import sys
import logging
from trial.config import Config
Config.load()
# setup logging to file
logging.basicConfig(
# filename="logs/bot.log",
# filemode="a+",
format="%(asctime)s - %(levelname)s -> %(message)s",
datefmt="%d-%m-%Y %H:%M:%S",
level=logging.INFO,
)
logging.getLogger("lavalink").setLevel(logging.WARNING)
logging.getLogger("nextcord").setLevel(logging.WARNING)
logging.getLogger("wikipediaapi").setLevel(logging.WARNING)
def load_cogs(bot):
bot.load_extension("trial.Cogs.VoiceBase")
for f in os.listdir("./trial/Cogs"):
if f.endswith(".py") and ("VoiceBase" not in f):
bot.load_extension(f"trial.Cogs.{f[:-3]}")
intents = Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(
command_prefix=Config.PREFIX,
intents=intents,
)
bot._enable_debug_events = True
# testing mode is enabled by passing "test" as command line argument
bot.testing = len(sys.argv) > 1 and sys.argv[1] == "debug"
bot_activity = Activity(
type=ActivityType.listening,
name=f"{f'{Config.PREFIX}help' if not bot.testing else 'debug'}",
)
@bot.event
async def on_ready():
try:
with open("logs/guilds.txt", "w") as f:
for guild in bot.guilds:
f.write(f"{guild.id}-{guild.name}\n")
except FileNotFoundError:
pass
load_cogs(bot)
await bot.change_presence(
status=bot.status,
activity=bot_activity,
)
logging.info(f"{Config.PREFIX}start. Bot is ready")
# this check is needed because if the list is empty
# nextcord raise an exception
if Config.TEST_GUILD_IDS:
@bot.slash_command(guild_ids=Config.TEST_GUILD_IDS)
async def test_one(interaction):
await interaction.response.send_message("TEST 1")
@bot.slash_command(guild_ids=Config.TEST_GUILD_IDS)
async def test_two(interaction, message):
await interaction.response.send_message(f"{message}")
if __name__ == "__main__":
bot.run(Config.TOKEN)