-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
108 lines (87 loc) · 3.45 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from __future__ import annotations
import logging
import traceback
import os
from datetime import datetime as dt
import aiohttp
import discord
from discord.ext import commands
import mystbin
import creds
from utils.context import RContext
from jishaku.help_command import MinimalEmbedPaginatorHelp
def get_prefix(bot, msg):
return commands.when_mentioned_or(*bot.prefixes)(bot, msg)
initial_extensions = (
"jishaku",
"cogs.buttons",
"cogs.events",
"cogs.misc",
"cogs.owner",
# "cogs.slash"
)
log = logging.getLogger("discord")
log.setLevel(logging.INFO)
handler = logging.FileHandler(filename="discord.log", encoding="utf-8", mode="w")
handler.setFormatter(logging.Formatter("%(asctime)s | %(levelname)s | %(name)s -> %(message)s"))
log.addHandler(handler)
class RoboAy(commands.Bot):
def __init__(self):
super().__init__(command_prefix = get_prefix,
description = "Personal bot made to test some things",
case_insensitive = True,
help_command = MinimalEmbedPaginatorHelp(),
intents = discord.Intents.all(),
allowed_mentions = discord.AllowedMentions.none(),
status = discord.Status.online,
activity = discord.Activity(type=discord.ActivityType.playing, name="owo help"),
owner_ids = {681183140357865474, 803147022374535189}
)
self._BotBase__cogs = commands.core._CaseInsensitiveDict()
self.session = aiohttp.ClientSession()
self.mystbin = mystbin.Client(session=self.session)
self.prefixes = ["owo ", "ra ", "Ra ", "Owo"]
self.creds = creds
async def on_ready(self):
if not hasattr(self, 'uptime'):
self.uptime = dt.utcnow()
log.info("Logged in")
print(f"Logged in as {self.user}\nID: {self.user.id}")
print(f"Discord Version: {discord.__version__}")
async def process_commands(self, msg: discord.Message):
ctx = await self.get_context(msg, cls=RContext)
try:
await self.invoke(ctx)
except Exception as e:
log.error("Error processing message")
raise e
async def on_message(self, msg: discord.Message):
if msg.author.bot:
return
if msg.guild.get_member(681183140357865474) is None: # make sure im in server commands are being used in
return
if msg.content in (
f"<@{self.user.id}>",
f"<@!{self.user.id}>"
):
await msg.channel.send("My prefix is `owo `")
await self.process_commands(msg)
async def on_message_edit(self, before: discord.Message, after: discord.Message):
if before.content != after.content:
await self.process_commands(after)
os.environ['JISHAKU_NO_UNDERSCORE'] = 'True'
os.environ['JISHAKU_NO_DM_TRACEBACK'] = 'True'
os.environ['JISHAKU_HIDE'] = 'True'
os.environ['NO_COLOR'] = 'True'
def run(self, *args, **kwargs):
for ext in initial_extensions:
try:
self.load_extension(ext)
log.info(f"{ext} has loaded.")
except Exception as e:
log.critical(f"'{ext}' did not load. Traceback: {e}")
traceback.print_exc()
super().run(creds.standle_token, reconnect=True, *args, **kwargs)
if __name__ == "__main__":
bot = RoboAy()
bot.run()