-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
59 lines (43 loc) · 1.5 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
import os
import sys
import traceback
from typing import Any
import discord
import yaml
from aiohttp import ClientSession
from discord.ext import commands
# Define function to process yaml config file
def process_config_file() -> Any:
with open("config.yaml", "r") as stream:
config_options = yaml.safe_load(stream)
return config_options
class PythonInsultBot(commands.Bot):
async def start(self, *args: str, **kwargs: str) -> None:
async with ClientSession() as self.session:
await super().start(*args, **kwargs)
def main() -> None:
intents = discord.Intents.default()
intents.guilds = True
bot = PythonInsultBot(
command_prefix=">", description="Python Discord Insult Bot", intents=intents
)
bot.conf_options = process_config_file()
for filename in os.listdir("./modules/cogs/"):
if filename.endswith(".py"):
try:
bot.load_extension(f"modules.cogs.{filename}".strip(".py"))
except Exception:
print(f"Failed to load extension modules.cogs.{filename}.", file=sys.stderr)
traceback.print_exc()
@bot.event
async def on_message(message: discord.Message) -> None:
"""
on_message event.
"""
if message.author.bot:
return
print(f"{message.author}: {message.content}")
await bot.process_commands(message)
bot.run(bot.conf_options["APP"]["ACCESS_TOKEN"], bot=True)
if __name__ == "__main__":
main()