· 4 years ago · Jan 16, 2021, 01:24 AM
1import discord
2from discord.ext import commands
3import os
4import sqlite3
5
6db = sqlite3.connect('main.sqlite3')
7cursor = db.cursor()
8cursor.execute('''
9CREATE TABLE IF NOT EXISTS main(
10 guild_id TEXT,
11 msg TEXT,
12 channel_id TEXT
13
14)
15''')
16
17
18
19#the discord blue color
20THEME1 = 0x7289da
21
22#the discord gray color
23THEME2 = 0x99aab5
24
25#the discord black color
26THEME3 = 0x23272a
27
28
29class System(commands.Cog):
30 def __init__(self, bot):
31 self.bot = bot
32
33
34 @commands.command()
35 @commands.guild_only()
36 async def e(self, ctx):
37
38
39 await ctx.send("Cogs - Fun cog is ||ON||")
40
41
42 @commands.Cog.listener()
43 async def on_member_join(self, member):
44 db = sqlite3.connect('main.sqlite3')
45 cursor = db.cursor()
46 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {member.guild.id}")
47 result = cursor.fetchone()
48 if result == None:
49 return
50
51 else :
52 cursor.execute(f"SELECT msg FROM main WHERE guild_id = {member.guild.id}")
53 result1 = cursor.fetchone()
54 member_count = len(list(member.guild.members))
55 mention = member.mention
56 user = member.name
57 guild = member.guild
58 embed = discord.Embed(color = member.color , description = str(result1[0]).format(member = member_count , mention = mention , user = user , guild = guild))
59 embed.set_thumbnail(url = f"{member.avatar_url}")
60 embed.set_author(name = f"{member.name}" , icon_url = f"{member.avatar_url}")
61
62
63 channel = self.bot.get_channel(id =int(result[0]))
64 await channel.send(embed = embed)
65
66
67 @commands.group(invoke_without_command = True)
68 async def welcome(self , ctx):
69 em = discord.Embed(color = THEME1)
70 em.add_field(name = "To set a channel " , value = "do `welcome channel` and add the channel you want " , inline = False)
71 em.add_field(name = "To set a channel welcome message " , value = "do `welcome message` and add ypur message to mention somone do {user} to mention the server do {guild} \n\n> more comming soon")
72 await ctx.send(embed = em)
73
74
75
76
77 @welcome.command()
78 async def channel(self, ctx , channel:discord.TextChannel):
79 db = sqlite3.connect('main.sqlite3')
80 cursor = db.cursor()
81 cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {ctx.guild.id}")
82 result = cursor.fetchone()
83 if result == None:
84 sql = ("INSERT INTO main(guild_id, channel_id) VALUES( ?, ?)")
85 val = (ctx.guild.id , channel.id)
86 embed = discord.Embed(color = 0x99aab5)
87 embed.add_field(name = f"channel has been set to {channel.mention}" , value = "> succes")
88 await ctx.send(embed = embed)
89 cursor.execute(sql , val)
90
91 elif result is not None:
92 sql = ("UPDATE main SET channel_id = ? WHERE guild_id = ?")
93 val = (channel.id , ctx.guild.id)
94 embed = discord.Embed(color = 0x99aab5)
95 embed.add_field(name = f"channel has been updated to {channel.mention}" , value = "> success !")
96 await ctx.send(embed = embed)
97 cursor.execute(sql , val)
98 db.commit()
99 cursor.close()
100 db.close()
101
102 @welcome.command()
103 async def message(self ,ctx , * , text):
104 db = sqlite3.connect('main.sqlite3')
105 cursor = db.cursor()
106 cursor.execute(f"SELECT msg FROM main WHERE guild_id = {ctx.guild.id}")
107 result = cursor.fetchone()
108 if result == None:
109 sql = ("INSERT INTO main(guild_id, msg) VALUES( ?, ?)")
110 val = (ctx.guild.id , text)
111 embed = discord.Embed(color = 0x99aab5)
112 embed.add_field(name = f"message has been succefully set to ```{text}```!" , value = "> success")
113 await ctx.send(embed = embed)
114 cursor.execute(sql , val)
115
116
117 elif result is not None:
118 sql = ("UPDATE main SET msg = ? WHERE guild_id = ?")
119 val = (text, ctx.guild.id)
120 embed = discord.Embed(color = 0x7289da)
121 embed.add_field(name = f"message has been succefully updated to ```{text}```!" , value = "succes")
122 await ctx.send(embed = embed)
123 cursor.execute(sql , val)
124 db.commit()
125 cursor.close()
126 db.close()
127
128 @commands.command()
129 async def data(self, ctx):
130 db = sqlite3.connect('main.sqlite3')
131 cursor = db.cursor()
132 cursor.execute(f"SELECT msg FROM main WHERE guild_id = {ctx.guild.id}")
133 result = self.cursor.fetchone()
134 await ctx.send(f"{result} data status")
135
136
137
138
139
140def setup(bot):
141 bot.add_cog(System(bot))
142 print("Systems cog is enabled now")