-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
72 lines (55 loc) · 2.21 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
""" Main bot file, run this file to start the bot """
import json
import discord
from discord.ext import commands
import methods
def get_prefix(_bot, _message):
""" Function to get the prefix for dynamic updating """
try:
with open(CONFIG_FILE) as i:
prefix_data = json.load(i)
return prefix_data["prefix"]
except FileNotFoundError as error:
print(error)
intents = discord.Intents(messages=True, guilds=True, members=True, reactions=True)
bot = commands.Bot(command_prefix=get_prefix, case_insensitive=True, reconnect=True,
check="blacklist_check", intents=intents)
bot.remove_command("help")
CONFIG_FILE = "data/config.json"
BLACKLISTED_FILE = "data/blacklisted.json"
data = methods.get_config()
cogs = [
"cogs.events",
"cogs.errors",
"cogs.users",
"cogs.tickets",
"cogs.moderation",
"cogs.help",
"cogs.admin"
]
@bot.event
async def on_ready():
""" Event that is called once bot is up and running, changes status and activity """
config = methods.get_config()
prefix = config["prefix"]
status = config["playing_status"]
online_status = config["online_status"]
if status != "" and online_status != "":
activity = discord.Activity(name=status, type=discord.ActivityType.playing)
await bot.change_presence(status=discord.Status(f"{online_status}"), activity=activity, afk=True)
elif status != "" and online_status == "":
activity = discord.Activity(name=status, type=discord.ActivityType.playing)
await bot.change_presence(activity=activity, afk=True)
elif online_status != "" and status == "":
await bot.change_presence(status=discord.Status(f"{online_status}"), afk=True)
print(f"Logged in as {bot.user.name}, type {prefix}help for more information.")
@bot.check
async def blacklist_check(ctx):
""" Check that bot uses every time it is called to see if a user is blacklisted """
with open(BLACKLISTED_FILE) as blacklisted_file:
blacklisted = json.load(blacklisted_file)
return f"{ctx.message.author}" not in blacklisted["user"]
if __name__ == '__main__':
for extension in cogs:
bot.load_extension(extension)
bot.run(data["token"])