This repository was archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTGK.py
More file actions
98 lines (78 loc) · 3.21 KB
/
TGK.py
File metadata and controls
98 lines (78 loc) · 3.21 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
93
94
95
96
97
98
# Libs
import discord # For discord
import os
from discord.ext import commands # For discord
import json # For interacting with json
from pathlib import Path # For paths
import platform # For stats
import logging
import json
cwd = Path(__file__).parents[0]
cwd = str(cwd)
print(f"{cwd}\n-----")
#Defining a few things
secret_file = json.load(open(cwd+'/bot_config/secrets.json'))
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=commands.when_mentioned_or('>'), case_insensitive=True, intents=intents)
bot.config_token = secret_file['token']
logging.basicConfig(level=logging.INFO)
bot.remove_command('help')
bot.blacklisted_users = []
@bot.event
async def on_ready():
print(f"-----\nLogged in as: {bot.user.name} : {bot.user.id}\n-----\nMy current prefix is: -\n-----")
data = read_json("blacklist")
bot.blacklisted_users = data["blacklistedUsers"]
await bot.change_presence(activity=discord.Game(name=f"Hi, my names {bot.user.name}.\nUse > to interact with me!")) # This changes the bots 'activity'
@bot.event
async def on_message(message):
# Ignore messages sent by yourself
if message.author.bot:
return
# A way to blacklist users from the bot by not processing commands
# if the author is in the blacklisted_users list
if message.author.id in bot.blacklisted_users:
if message.content.startswith(">"):
return await message.reply( "Your blacklisted")
await bot.process_commands(message)
@bot.command()
async def blacklist(ctx, user: discord.Member):
if ctx.message.author.id == user.id:
await ctx.send("Hey, you cannot blacklist yourself!")
return
bot.blacklisted_users.append(user.id)
data = read_json("blacklist")
data["blacklistedUsers"].append(user.id)
write_json(data, "blacklist")
await ctx.send(f"Hey, I have blacklisted {user.name} for you.")
@bot.command()
async def unblacklist(ctx, user: discord.Member):
bot.blacklisted_users.remove(user.id)
data = read_json("blacklist")
data["blacklistedUsers"].remove(user.id)
write_json(data, "blacklist")
await ctx.send(f"Hey, I have unblacklisted {user.name} for you.")
@bot.command()
@commands.has_permissions(administrator=True)
async def load(ctx, extension):
bot.load_extension(f'cogs.{extension}')
print(f'The {extension} is loaded by {ctx.author.name}')
await ctx.send(f'The {extension} is successfully Loaded.')
@bot.command()
@commands.has_permissions(administrator=True)
async def unload(ctx, extension):
bot.unload_extension(f'cogs.{extension}')
print(f'The {extension} is unloaded by {ctx.author.name}')
await ctx.send(f'The {extension} is successfully unloaded.')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f'cogs.{filename[:-3]}')
def read_json(filename):
with open(f"{cwd}/bot_config/{filename}.json", "r") as file:
data = json.load(file)
return data
def write_json(data, filename):
with open(f"{cwd}/bot_config/{filename}.json", "w") as file:
json.dump(data, file, indent=4)
bot.run(bot.config_token) # Runs our bot