forked from R3tr0gh057/projectDEDSEC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdedsec.py
147 lines (124 loc) · 4.93 KB
/
dedsec.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
import os
from turtle import title
from discord.ext import commands
import discord
from dotenv import load_dotenv
from datetime import datetime
from discord.ext.commands import has_permissions, MissingPermissions
import time
import random
#update the exception handling later
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
client = commands.Bot(command_prefix='.')
@client.event
async def on_ready():
await client.change_presence(status = discord.Status.online, activity = discord.Game(".help"))
print('Logged in as {0.user}'.format(client))
for guild in client.guilds:
if guild.name == GUILD:
break
print(
f'{client.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})\n'
)
#members = '\n - '.join([member.name for member in guild.members])
#print(f'Guild Members:\n - {members}')
print(", ".join([member.name for member in guild.members]))
#mention's if someone deletes a message (4k)
@client.event
async def on_message_delete(ctx):
msg = f'{ctx.author} has deleted the message: {ctx.content}'
await ctx.channel.send(msg)
#client latency check
@client.command(name='ping', help='Returns the client latency.')
async def ping(ctx):
await ctx.channel.send(f'Client latency: {round(client.latency*1000)}ms')
#purge command
@client.command(name='purge', help='Clears (x) amount of messages.')
async def purge(ctx, amount: int):
await ctx.channel.purge(limit=amount)
#ban command
@client.command(name='ban', help='Ban someone for breaking a rule/other reasons')
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member,*,reason="No reason provided"):
for guild in client.guilds:
if guild.name == GUILD:
break
await ctx.channel.send(member.display_name+" has been banned from "+guild.name)
await member.ban(reason=reason)
try:
await member.send("You have been banned from "+guild.name+" for "+reason)
except:
print(member.name+" is not accepting dms")
#kick command
@client.command(name='kick', help='kick someone for breaking a rule/other reasons')
@commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member,*,reason="No reason provided"):
for guild in client.guilds:
if guild.name == GUILD:
break
await ctx.channel.send(member.display_name+" has been kicked from "+guild.name)
await member.kick(reason=reason)
try:
await member.send("You have been kicked from "+guild.name+" for "+reason)
except:
print(member.display_name+" is not accepting dms")
#unban command
@client.command(name='unban', help='unban a banned member')
@commands.has_permissions(ban_members = True)
async def unban(ctx,*,member):
for guild in client.guilds:
if guild.name == GUILD:
break
banned_users= await ctx.guild.bans()
member_name, member_disc =member.split('#')
for banned_entry in banned_users:
user=banned_entry.user
if (user.name, user.discriminator)==(member_name, member_disc):
await ctx.guild.unban(user)
await ctx.channel.send(member_name+" has been unbanned")
return
await ctx.send(member+" is not in the ban list")
try:
await member.send("You have been unbanned in "+guild.name)
except:
print(member.display_name+" is not accepting dms")
#mute command
@client.command(name='mute', help='mute a member')
@commands.has_permissions(kick_members = True)
async def mute(ctx, member : discord.Member):
muted_role= ctx.guild.get_role(937655146182246401)
await member.add_roles(muted_role)
await ctx.channel.send(member.mention+' has been muted')
#unmute command
@client.command(name='unmute', help='unmute a member')
@commands.has_permissions(kick_members = True)
async def unmute(ctx, member : discord.Member):
muted_role= ctx.guild.get_role(937655146182246401)
await member.remove_roles(muted_role)
await ctx.channel.send(member.mention+', your mute has been lifted')
#exception handling start
@ban.error
async def ban_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.channel.send("You dont have the perms to ban members")
@kick.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.channel.send("You dont have the perms to kick members")
@unban.error
async def unban_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.channel.send("You dont have the perms to unban members")
@mute.error
async def mute_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.channel.send("You dont have the perms to mute members")
@unmute.error
async def unban_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.channel.send("You dont have the perms to unmute members")
#exception handling end
client.run(TOKEN)