forked from jsmsj/GdriveCloneBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (53 loc) · 2.42 KB
/
main.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
import logging
from discord.ext import commands
import discord
import os
import cogs._config
import shutil,os
from cogs._helpers import embed
if os.path.exists('log.txt'):
with open('log.txt', 'r+') as f:
f.truncate(0)
logging.basicConfig(format='%(asctime)s,%(msecs)03d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
datefmt='%Y-%m-%d:%H:%M:%S',
handlers=[logging.FileHandler('log.txt'), logging.StreamHandler()],
level=logging.INFO)
logger = logging.getLogger(__name__)
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=cogs._config.prefix, intents=intents, help_command=None, case_insensitive=True)
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Game(name="Google Drive"))
print("Bot is ready!")
@bot.event
async def on_command_error(ctx:commands.Context,error):
if hasattr(ctx.command, 'on_error'):
return
if isinstance(error,commands.CommandNotFound):
return
elif isinstance(error,commands.CheckFailure):
await ctx.send(f"You do not have permission to run this command.\nOR\nYou have not authorized the bot with your account. Run `{cogs._config.prefix}auth` to authorize.\nOR\nYou are using a command related to service accounts, and have not authorized for it. Use `{cogs._config.prefix}authsa` to authorize for service accounts.")
else:
logger.warning(error)
_file=None
if os.path.exists('log.txt'):
_file = discord.File('log.txt')
await ctx.send(embed=embed(f'Error | {ctx.command.name}',f'An error occured, kindly report it to jsmsj#5252.\n```py\n{error}\n```\nHere is the attached logfile.')[0],file=_file)
if __name__ == '__main__':
# When running this file, if it is the 'main' file
# i.e. its not being imported from another python file run this
if os.path.exists('accounts'):
shutil.rmtree('accounts')
if os.path.exists('sas.zip'):
os.remove('sas.zip')
if os.path.exists('emails.txt'):
os.remove('emails.txt')
if os.path.exists('aacounts.zip'):
os.remove('aaccounts.zip')
if os.path.exists('sas'):
shutil.rmtree('sas')
for file in os.listdir("cogs/"):
if file.endswith(".py") and not file.startswith("_"):
bot.load_extension(f"cogs.{file[:-3]}")
logger.info("Bot has started, all cogs are loaded.")
bot.run(cogs._config.bot_token)