forked from NotOrca22/discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson_7.py
147 lines (125 loc) · 5.18 KB
/
lesson_7.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 discord
from discord.ext import commands
from discord.ext.commands import has_permissions
from random import randint, random
import mysql.connector
from dotenv import load_dotenv
import os
load_dotenv()
TOKEN = os.getenv("TOKEN")
client = commands.Bot(command_prefix='!', case_insensitive=True)
TOKEN = os.getenv("TOKEN")
HOST = os.getenv("HOST")
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
DATABASE = os.getenv("DATABASE")
connection = mysql.connector.connect(
host=HOST,
user=USERNAME,
password=PASSWORD,
database=DATABASE
)
@client.event
async def on_ready():
for guild in client.guilds:
print(
f'{client.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})'
)
for member in guild.members:
print(member)
@client.command()
@has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.channel.send(f"{member} has been kicked by {ctx.message.author}. Reason: {reason}.")
@client.command()
@has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason=None):
a = ctx.guild.roles
reason = 'None specified'
a.reverse()
for r in a:
if r not in member.roles:
if r in ctx.message.author.roles:
channel = await member.create_dm()
await channel.send(
f'{member.name}, you were banned from the server by {ctx.message.author}.'
f' | Reason: {reason}. You may contact them to appeal or get reinvited.'
)
await member.ban(reason=reason)
print(ctx.message.content)
await ctx.channel.send('%s has been banned by %s. Reason: %s' % (member, ctx.message.author, reason))
@client.command()
@has_permissions(ban_members=True)
async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
member.name, member.discriminator = member.split('#')
for bu in banned_users:
user = bu.user
if (user.name, user.discriminator) == (member.name, member.discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.name}#{user.discriminator}.')
@client.command()
async def coin(ctx, call):
if call == 'heads' or call == 'Heads' or call == 'HEADS':
if random() <= 0.5:
await ctx.channel.send('%s, you win! The coin came up heads!' % ctx.message.author)
else:
await ctx.channel.send('%s, you lost! The coin came up tails! Sorry! (not really)' % ctx.message.author)
if call == 'tails' or call == 'Tails' or call == 'TAILS':
a = random()
if a >= 0.5:
await ctx.channel.send('%s, you win! The coin came up tails!' % ctx.message.author)
else:
await ctx.channel.send('%s, you lost! The coin came up heads! Sorry! (not really)' % ctx.message.author)
@client.command()
@has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member = None, *, reason=None):
if member == ctx.message.author:
await ctx.channel.send('You cannot mute yourself. Orca-Bot-Whale does not allow self-harm.')
elif member is None:
await ctx.channel.send('You cannot mute nobody you imbecile!')
else:
role = discord.utils.get(ctx.guild.roles, name="Muted")
print(ctx.message.content)
if not member:
await ctx.channel.send('Please specify a member to mute')
return
await member.add_roles(role)
await ctx.channel.send('%s has been successfully muted by %s' % (member, ctx.message.author))
channel = await member.create_dm()
await channel.send(
f'{member.name}, you were muted in the server by {ctx.message.author}.'
f' | Reason: %s. You may contact them to appeal the mute.' % reason
)
@client.command()
@has_permissions(administrator=True)
async def unmute(ctx, member: discord.Member = None):
role = discord.utils.get(ctx.guild.roles, name="Muted")
print(ctx.message.content)
if not member:
await ctx.channel.send('Please specify a member to unmute.')
return
if role in member.roles:
await member.remove_roles(role)
await ctx.channel.send('%s has been successfully unmuted by %s' % (member, ctx.message.author))
channel = await member.create_dm()
await channel.send(
f'{member.name}, you were unmuted in the server by {ctx.message.author}. Great!'
)
else:
await ctx.channel.send('%s was never muted in the first place, %s!' % (member, ctx.message.author))
@client.command()
@has_permissions(kick_members=True)
async def warn(ctx, member: discord.Member, *, reason=None):
if member:
await ctx.channel.send('%s, you have been warned by %s. Reason: %s' % (member, ctx.message.author, reason))
else:
await ctx.channel.send('%s, please specify a member to warn' % (ctx.message.author))
channel = await member.create_dm()
await channel.send(
f'{member.name}, you were warned in the server by {ctx.message.author}.'
f' | Reason: %s.' % reason
)
client.run(TOKEN)