This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
125 lines (109 loc) · 5.69 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import discord
from discord.ext import commands
from utils.dataIO import fileIO
import cogs.tools as tools
from datetime import datetime
# Customization options can be found in settings.json!
# Please do not touch anything else unless
# you know what you're doing!
tools.settingscheck()
sett = fileIO("settings.json", "load")
if sett["TOKEN"] == "None":
answ = input("Please paste in your bot token and hit enter.\n")
sett["TOKEN"] = str(answ)
fileIO("settings.json", "save", sett)
def get_prefix(client, message):
tools.jsoncheck()
if not message.guild:
return commands.when_mentioned_or(default_prefix)(client, message)
prefixes = fileIO("data/write/prefix.json", "load")
if str(message.guild.id) not in prefixes:
return commands.when_mentioned_or(default_prefix)(client, message)
prefix = prefixes[str(message.guild.id)]
return commands.when_mentioned_or(prefix)(client, message)
extensions = ["help", "admin", "mod", "fun", "general", "strike", "merit", "setup"]
default_prefix = sett["DEFAULT_PREFIX"]
token = sett["TOKEN"]
presence = sett["PRESENCE"]
client = commands.Bot(command_prefix=get_prefix, case_insensitive=True, help_command=None)
# Cog Loading
@client.command()
async def unload(ctx, extension):
if await client.is_owner(ctx.message.author) == True:
try:
client.unload_extension(extension)
print(">>>Unloaded {}".format(extension))
embed=discord.Embed(title="🔵 {}".format(client.user.name), description="Unloaded {}.".format(extension), color=0x55acee, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
except Exception as error:
print("{} cannot be unloaded. [{}]".format(extension, error))
embed=discord.Embed(title="🔴 Error", description="{} cannot be unloaded.\n[{}]".format(extension, error), color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🔴 Error", description="Only my owner can do that.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
@client.command()
async def reload(ctx, extension):
if await client.is_owner(ctx.message.author) == True:
try:
client.reload_extension("cogs." + extension)
print(">>>Reloaded {}".format(extension))
embed=discord.Embed(title="🔵 {}".format(client.user.name), description="Reloaded {}.".format(extension), color=0x55acee, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
except Exception as error:
print("{} cannot be reloaded. [{}]".format(extension, error))
embed=discord.Embed(title="🔴 Error", description="{} cannot be reloaded.\n[{}]".format(extension, error), color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🔴 Error", description="Only my owner can do that.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
@client.command()
async def load(ctx, extension):
if await client.is_owner(ctx.message.author) == True:
try:
client.load_extension("cogs." + extension)
print(">>>Loaded {}".format(extension))
embed=discord.Embed(title="🔵 {}".format(client.user.name), description="Loaded {}.".format(extension), color=0x55acee, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
except Exception as error:
print("{} cannot be loaded. [{}]".format(extension, error))
embed=discord.Embed(title="🔴 Error", description="{} cannot be loaded.\n[{}]".format(extension, error), color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🔴 Error", description="Only my owner can do that.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=client.user.avatar_url, text="{}".format(client.user.name))
await ctx.send(embed=embed)
# Startup
@client.event
async def on_ready():
print(" ")
print("--------------------------------------------------")
print(" ")
print("OpenBot online!")
print(" ")
print("Client user name:")
print(str(client.user))
print(" ")
print("Default prefix:")
print(default_prefix)
print(" ")
print("Currently in {} guilds.".format(len(client.guilds)))
print(" ")
print("--------------------------------------------------")
print(" ")
await client.change_presence(status=discord.Status.online, activity=discord.Streaming(name=presence, url='https://www.twitch.tv/directory', twitch_name="directory"))
if __name__ == "__main__":
for extension in extensions:
#try:
client.load_extension("cogs." + extension)
#except Exception as error:
# print("{} cannot be loaded. [{}]".format(extension, error))
client.run(token)