This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
forked from kkrypt0nn/Python-Discord-Bot-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowner-normal.py
150 lines (136 loc) · 4.71 KB
/
owner-normal.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
""""
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
Description:
This is a template to create your own discord bot in python.
Version: 4.1
"""
import json
import disnake
from disnake.ext import commands
from disnake.ext.commands import Context
from helpers import json_manager, checks
class Owner(commands.Cog, name="owner-normal"):
def __init__(self, bot):
self.bot = bot
@commands.command(
name="shutdown",
description="Make the bot shutdown.",
)
@checks.is_owner()
async def shutdown(self, context: Context):
"""
Makes the bot shutdown.
"""
embed = disnake.Embed(
description="Shutting down. Bye! :wave:",
color=0x9C84EF
)
await context.send(embed=embed)
await self.bot.close()
@commands.command(
name="say",
description="The bot will say anything you want.",
)
@checks.is_owner()
async def say(self, context: Context, *, message: str):
"""
The bot will say anything you want.
"""
await context.send(message)
@commands.command(
name="embed",
description="The bot will say anything you want, but within embeds.",
)
@checks.is_owner()
async def embed(self, context: Context, *, message: str):
"""
The bot will say anything you want, but within embeds.
"""
embed = disnake.Embed(
description=message,
color=0x9C84EF
)
await context.send(embed=embed)
@commands.group(
name="blacklist"
)
async def blacklist(self, context: Context):
"""
Lets you add or remove a user from not being able to use the bot.
"""
if context.invoked_subcommand is None:
with open("blacklist.json") as file:
blacklist = json.load(file)
embed = disnake.Embed(
title=f"There are currently {len(blacklist['ids'])} blacklisted IDs",
description=f"{', '.join(str(id) for id in blacklist['ids'])}",
color=0x9C84EF
)
await context.send(embed=embed)
@blacklist.command(
name="add"
)
async def blacklist_add(self, context: Context, member: disnake.Member = None):
"""
Lets you add a user from not being able to use the bot.
"""
try:
user_id = member.id
with open("blacklist.json") as file:
blacklist = json.load(file)
if user_id in blacklist['ids']:
embed = disnake.Embed(
title="Error!",
description=f"**{member.name}** is already in the blacklist.",
color=0xE02B2B
)
return await context.send(embed=embed)
json_manager.add_user_to_blacklist(user_id)
embed = disnake.Embed(
title="User Blacklisted",
description=f"**{member.name}** has been successfully added to the blacklist",
color=0x9C84EF
)
with open("blacklist.json") as file:
blacklist = json.load(file)
embed.set_footer(
text=f"There are now {len(blacklist['ids'])} users in the blacklist"
)
await context.send(embed=embed)
except:
embed = disnake.Embed(
title="Error!",
description=f"An unknown error occurred when trying to add **{member.name}** to the blacklist.",
color=0xE02B2B
)
await context.send(embed=embed)
@blacklist.command(
name="remove"
)
async def blacklist_remove(self, context, member: disnake.Member = None):
"""
Lets you remove a user from not being able to use the bot.
"""
try:
user_id = member.id
json_manager.remove_user_from_blacklist(user_id)
embed = disnake.Embed(
title="User removed from blacklist",
description=f"**{member.name}** has been successfully removed from the blacklist",
color=0x9C84EF
)
with open("blacklist.json") as file:
blacklist = json.load(file)
embed.set_footer(
text=f"There are now {len(blacklist['ids'])} users in the blacklist"
)
await context.send(embed=embed)
except:
embed = disnake.Embed(
title="Error!",
description=f"**{member.name}** is not in the blacklist.",
color=0xE02B2B
)
await context.send(embed=embed)
def setup(bot):
bot.add_cog(Owner(bot))