-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNarukamiBot.py
More file actions
92 lines (75 loc) · 3.01 KB
/
NarukamiBot.py
File metadata and controls
92 lines (75 loc) · 3.01 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
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
import discord
from discord.ext import commands
import logging
from pathlib import Path
import os
from discord.ext.commands import CommandNotFound, MissingPermissions, MissingRequiredArgument
from dotenv import load_dotenv
cwd = Path(__file__).parents[0]
cwd = str(cwd)
print(f"\nWorking dir:{cwd}")
load_dotenv()
owner = int(os.getenv("OWNER_ID"))
prefix = os.getenv("PREFIX")
bot = commands.Bot(command_prefix=prefix, case_insensitive=True)
logging.basicConfig(level=logging.INFO)
@bot.event
async def on_ready():
print(f'{bot.user.name} with id:{bot.user.id} is now ready!\nCurrent bot prefix is: {prefix}') # Just for the terminal
print(f'The current owner id is: {owner}')
await bot.change_presence(activity=discord.Game(name=f"Persona 5 Royal {prefix}help")) # Sets Status
# await bot.change_presence(activity=discord.Game(name=f"Phoenix Wright: Ace Attorney")) # Used for upcoming AdachiBot
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, MissingRequiredArgument):
await ctx.send(f'{ctx.author}, you are missing 1 or more arguments for this command!')
return
elif isinstance(error, MissingPermissions):
await ctx.send(f'{ctx.author} does not have permission for this command!')
return
elif isinstance(error, CommandNotFound):
await ctx.send(f'Command not found, Use {prefix}help to see a list of avaiable commands.')
return
raise error
@bot.command(pass_context=True)
async def load(ctx, extension=''):
if ctx.message.author.id == owner:
if extension == '':
await ctx.send("Please enter the Category to load")
else:
bot.load_extension(f'cogs.{extension}')
else:
await ctx.send("You do not have permission for this command")
@bot.command(pass_context=True)
async def reload(ctx, extension=''):
if ctx.message.author.id == owner:
if extension == '':
await ctx.send("Please enter the Category to reload")
else:
bot.unload_extension(f'cogs.{extension}')
bot.load_extension(f'cogs.{extension}')
await ctx.send(f'Reloading {extension}')
else:
await ctx.send("You do not have permission for this command")
@bot.command()
async def unload(ctx, extension=''):
if ctx.message.author.id == owner:
if extension == '':
await ctx.send("Please enter the Category to load")
else:
bot.unload_extension(f'cogs.{extension}')
else:
await ctx.send("You do not have permission for this command")
@bot.command()
async def shutdown(ctx):
if ctx.author.id == owner:
message = f'{ctx.author} is authorized, Shutting Down Bot......'
await ctx.send(message)
await bot.logout()
await bot.close()
else:
await ctx.send(f'{ctx.author} is not authorized to shut down this bot')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f'cogs.{filename[:-3]}')
bot.run(os.getenv("TOKEN")) # Turns the bot on