· 4 years ago · Aug 11, 2021, 02:12 PM
1@client.command()
2async def setwelcomechannel(ctx, channel: discord.TextChannel):
3
4 db = sqlite3.connect('memes.sqlite')
5
6 cursor = db.cursor()
7
8
9 cursor.execute("SELECT channel_id FROM memes WHERE guild_id = ?", (ctx.guild.id,))
10 result = cursor.fetchone()
11 if result is None:
12 sql = ("INSERT INTO memes(guild_id, channel_id) VALUES(?,?)")
13 val = (ctx.guild.id, channel.id)
14 elif result is not None:
15 sql = ("UPDATE memes SET channel_id = ? WHERE guild_id = ?")
16 val = (channel.id, ctx.guild.id)
17 cursor.execute(sql,val)
18 db.commit()
19 cursor.close()
20 db.close()
21 await ctx.send(f"New welcome channel has been set to: {channel.mention}")
22 await channel.send("This is the new welcome channel")
23
24@client.event
25async def on_member_join(member):
26 inviter = await tracker.fetch_inviter(member)
27 await client.wait_until_ready()
28 db = sqlite3.connect('memes.sqlite')
29 cursor = db.cursor()
30 cursor.execute("SELECT channel_id FROM memes WHERE guild_id = ?", (member.guild.id,))
31 result = cursor.fetchone()
32 if not result:
33 return
34 channelloo = result[0]
35 final_channel = member.guild.get_channel(int(channelloo))
36 await final_channel.send(f'{member.mention} has just joined invited by {inviter.mention}')
37
38@client.command()
39async def setleavechannel(ctx, channel: discord.TextChannel):
40 db = sqlite3.connect('leave.sqlite')
41
42 cursor = db.cursor()
43
44 cursor.execute("SELECT channel_id FROM leave WHERE guild_id = ?", (ctx.guild.id,))
45 result = cursor.fetchone()
46 if result is None:
47 sql = ("INSERT INTO leave(guild_id, channel_id) VALUES(?,?)")
48 val = (ctx.guild.id, channel.id)
49 elif result is not None:
50 sql = ("UPDATE leave SET channel_id = ? WHERE guild_id = ?")
51 val = (channel.id, ctx.guild.id)
52 cursor.execute(sql,val)
53 db.commit()
54 cursor.close()
55 db.close()
56 await ctx.send(f"New Leaves channel has been set to {channel.mention}")
57
58@client.event
59async def on_member_remove(member):
60 await client.wait_until_ready()
61 db = sqlite3.connect('leave.sqlite')
62 cursor = db.cursor()
63 cursor.execute("SELECT channel_id FROM leave WHERE guild_id = ?", (member.guild.id,))
64 result = cursor.fetchone()
65 if not result:
66 return
67 channelloo = result[0]
68 final_channel = member.guild.get_channel(int(channelloo))
69 await final_channel.send(f'{member.mention} has just left.')
70
71@client.event
72async def on_ready():
73 db2 = sqlite3.connect('leave.sqlite')
74 cursor2 = db2.cursor()
75 cursor2.execute('''
76 CREATE TABLE IF NOT EXISTS leabe(
77 guild_id TEXT,
78 channel_id TEXT
79 )
80 ''')
81 db2.commit()
82
83 db3 = sqlite3.connect('memes.sqlite')
84 cursor3 = db3.cursor()
85 cursor3.execute('''
86 CREATE TABLE IF NOT EXISTS memes(
87 guild_id TEXT,
88 channel_id TEXT
89 )
90 ''')
91 db3.commit()