· 4 years ago · Feb 20, 2021, 08:14 AM
1import discord
2from discord.ext import commands
3import random
4import sqlite3
5
6#VARIABLES
7bot = discord.Client()
8bot = commands.Bot(command_prefix="-", case_insensitive=True)
9intents = discord.Intents.default()
10intents.members = True
11intents.guilds = True
12TOKEN = 'ODExNTIxMTU0NTMxNTkwMTc0.YCzZ-A.7u1JuJoExTqtX7i9LjFKf7kgRdg'
13
14c = [
15 0x00ffff,
16 0x66ffff,
17 0x99ffcc,
18 0x99ff99,
19 0x66ffcc,
20 0x00ffcc,
21 0x00ff99,
22 0x66ff99,
23 0x99ff66,
24 0x66ff66,
25 0x00ff00,
26 0x66ff33,
27 0x99ff33,
28 0xccff66,
29 0xccff33,
30 0xccff99]
31
32#ON READY
33@bot.event
34async def on_ready():
35 db = sqlite3.connect('main.sqlite')
36 cursor = db.cursor()
37 cursor.execute('''
38 CREATE TABLE IF NOT EXISTS main(
39 guild_id TEXT,
40 channel_id TEXT
41 )
42 ''')
43 print('Logging Leopard ready to start logging stuff!')
44
45#HELP COMMAND
46
47@bot.remove_command('help')
48
49@bot.command()
50async def help(ctx):
51 pass
52
53#LOGGING COMMANDS
54@bot.command(name="logging")
55async def logging(ctx):
56 await ctxsend('Available logging commands: \n\n`-logging_enable [#channel]` \n`-logging_disable` \n\n\nMake sure to include the underscores( _ ) too.')
57
58@bot.command(name="logging_enable")
59async def logging_enable(ctx, channel : discord.TextChannel):
60 if ctx.author.guild_permissions.manage_messages:
61 db = sqlite3.connect('main.sqlite')
62 cursor = db.cursor()
63 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {ctx.guild.id}")
64 result = cursor.fetchone()
65
66 if result == None:
67 sql = ("INSERT INTO main(guild_id, channel_id) VALUES(?,?)")
68 val = (ctx.guild.id, channel.id)
69 await ctx.send(f'Logging channel has been set to {channel.mention}. All updates will be logged there.')
70
71 elif result is not None:
72 sql = ("UPDATE main SET channel_id = ?, WHERE guild_id = ?")
73 val = (channel.id, ctx.guild.id)
74 await ctx.send(f'Logging channel has been updated to {channel.mention}. All updates will be logged there.')
75 cursor.execute(sql, val)
76 db.commit()
77 cursor.close()
78 db.close()
79
80@bot.command(name="logging_disable")
81async def logging_disable(ctx, channel:discord.TextChannel):
82 if ctx.author.guild_permissions.manage_messages:
83 db = sqlite3.connect('main.sqlite')
84 cursor = db.cursor()
85 sql = (f"DELETE FROM main WHERE channel_id = ? and guild_id = ?")
86 val = (channel.id, ctx.guild.id)
87 cursor.execute(sql, val)
88 db.commit()
89 cursor.close()
90 db.close()
91 await ctx.send(f"Stopped logging updates for {ctx.guild}")
92
93#LOGGING EVENTS:
94
95@bot.event
96async def on_member_join(member):
97 db = sqlite3.connect('main.sqlite')
98 cursor = db.cursor()
99 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {member.guild.id}")
100 result = cursor.fetchone()
101 if result is None:
102 print('No log channel was set')
103 else:
104 db = sqlite3.connect('main.sqlite')
105 cursor = db.cursor()
106 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {member.guild.id}")
107 result = cursor.fetchone()
108 channel = bot.get_channel(id=int(result[0]))
109 memberjoinembed = discord.Embed(title="Member Joined | <:tick:803237917354622996>", description=f"A new member has joined. \n\n**Username:** {member.display_name} \n**ID:** {member.id} \n**Account Created At:** {member.created_at} \n**Joined At:** {member.joined_at}", color=random.choice(c))
110 memberjoinembed.set_thumbnail(url=member.avatar_url)
111 memberjoinembed.set_footer(text=f"{member.display_name}", icon_url=member.avatar_url)
112 await channel.send(embed=memberjoinembed)
113 print('Sent log!')
114
115@bot.event
116async def on_message(message):
117 db = sqlite3.connect('main.sqlite')
118 cursor = db.cursor()
119 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {message.guild.id}")
120 result = cursor.fetchone()
121 if result is None:
122 print('Log channel was not set')
123 else:
124 if message.author == bot.user:
125 return
126 db = sqlite3.connect('main.sqlite')
127 cursor = db.cursor()
128 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {message.guild.id}")
129 result = cursor.fetchone()
130 channel = bot.get_channel(id=int(result[0]))
131 newmsgembed = discord.Embed(title="New Message Sent!", description=f"A new message was just sent: \n\n**Content:** `{message.content}` \n**Channel:** {message.channel.mention} \n**Author:** {message.author} \n**ID:** {message.id}", color=random.choice(c), timestamp=message.created_at)
132 await channel.send(embed=newmsgembed)
133
134@bot.event
135async def on_message_delete(message):
136 db = sqlite3.connect('main.sqlite')
137 cursor = db.cursor()
138 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {message.guild.id}")
139 result = cursor.fetchone()
140 if result is None:
141 print('Log channel was not set')
142 else:
143 if message.author == bot.user:
144 return
145 db = sqlite3.connect('main.sqlite')
146 cursor = db.cursor()
147 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {message.guild.id}")
148 result = cursor.fetchone()
149 channel = bot.get_channel(id=int(result[0]))
150 msgdelemb = discord.Embed(title="Message Deleted", description=f"A message was just deleted: \n\n**Content:** {message.content} \n**Channel:** {message.channel.mention} \n**Author:** {message.author}", color=random.choice(c), timestamp=message.created_at)
151 await channel.send(embed=msgdelemb)
152
153 await process_commands(message)
154
155bot.run(TOKEN)