· 4 years ago · Feb 18, 2021, 10:10 AM
1@bot.event
2async def on_ready():
3 db = sqlite3.connect('main.sqlite')
4 cursor = db.cursor()
5 cursor.execute('''
6 CREATE TABLE IF NOT EXISTS main(
7 guild_id TEXT,
8 channel_id TEXT
9 )
10 ''')
11 print('Logging Leopard ready to start logging stuff!')
12
13#HELP COMMAND
14
15@bot.remove_command('help')
16
17@bot.command()
18async def help(ctx):
19 pass
20
21#LOGGING COMMANDS
22@bot.command(name="logging")
23async def logging(ctx):
24 await ctx.send('Available logging commands: \n\n`-logging_enable [#channel]` \n`-logging_disable` \n\n\nMake sure to include the underscores( _ ) too.')
25
26@bot.command(name="logging_enable")
27async def logging_enable(ctx, channel : discord.TextChannel):
28 if ctx.author.guild_permissions.manage_messages:
29 db = sqlite3.connect('main.sqlite')
30 cursor = db.cursor()
31 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {ctx.guild.id}")
32 result = cursor.fetchone()
33
34 if result == None:
35 sql = ("INSERT INTO main(guild_id, channel_id) VALUES(?,?)")
36 val = (ctx.guild.id, channel.id)
37 await ctx.send(f'Logging channel has been set to {channel.mention}. All updates will be logged there.')
38
39 elif result is not None:
40 sql = ("UPDATE main SET channel_id = ?, WHERE guild_id = ?")
41 val = (channel.id, ctx.guild.id)
42 await ctx.send(f'Logging channel has been updated to {channel.mention}. All updates will be logged there.')
43 cursor.execute(sql, val)
44 db.commit()
45 cursor.close()
46 db.close()
47
48@bot.command(name="logging_disable")
49async def logging_disable(ctx):
50 if ctx.author.guild_permissions.manage_messages:
51 db = sqlite3.connect('main.sqlite')
52 cursor = db.cursor()
53 cursor.execute("DELETE FROM main WHERE channel_id = ? and guild_id = ?")
54 db.commit()
55 cursor.close()
56 db.close()
57 await ctx.send(f"Stopped logging updates for {ctx.guild}")
58
59#LOGGING EVENTS:
60
61@bot.event
62async def on_member_join(member):
63 db = sqlite3.connect('main.sqlite')
64 cursor = db.cursor()
65 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {member.guild.id}")
66 result = cursor.fetchone()
67 if result is None:
68 pass
69 else:
70 db = sqlite3.connect('main.sqlite')
71 cursor = db.cursor()
72 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {member.guild.id}")
73 result = cursor.fetchone()
74 channel = bot.get_channel(id=int(result[0]))
75 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))
76 memberjoinembed.set_thumbnail(url=member.avatar_url)
77 memberjoinembed.set_footer(text=f"{member.display_name}", icon_url=member.avatar_url)
78 await channel.send(embed=memberjoinembed)
79
80bot.run(TOKEN)
81