· 4 years ago · Feb 21, 2021, 10:20 AM
1#IMPORTING STUFF
2import discord
3from discord.ext import commands
4import random
5import sqlite3
6
7#VARIABLES
8bot = discord.Client()
9bot = commands.Bot(command_prefix="+", case_insensitive=True)
10intents = discord.Intents.default()
11intents.members = True
12intents.guilds = True
13Token = Token
14
15c = [
16 0x00ffff,
17 0x66ffff,
18 0x99ffcc,
19 0x99ff99,
20 0x66ffcc,
21 0x00ffcc,
22 0x00ff99,
23 0x66ff99,
24 0x99ff66,
25 0x66ff66,
26 0x00ff00,
27 0x66ff33,
28 0x99ff33,
29 0xccff66,
30 0xccff33,
31 0xccff99]
32
33#ON READY
34@bot.event
35async def on_ready():
36 db = sqlite3.connect('welcome.sqlite')
37 cursor = db.cursor()
38 cursor.execute('''
39 CREATE TABLE IF NOT EXISTS welcome(
40 channel_id TEXT,
41 msg RTL TEXT,
42 footer RTL TEXT,
43 icon IMAGE,
44 title RTL TEXT,
45 guild_id RTL TEXT
46 )
47 ''')
48 print('Welcoming Whale read to welcome new members!')
49
50#HELP
51@bot.remove_command('help')
52
53
54@bot.command(name="help")
55async def help(ctx):
56 pass
57
58#WELCOME CONFIG
59
60@bot.command(name="welcome")
61async def welcome(ctx):
62 welcembed = discord.Embed(colour=random.choice(c), timestamp=ctx.message.created_at)
63 welcembed.add_field(name="Available Welcome Commands:", value="`+welcome_enable [#channel]` | `+welcome_disable [#channel]` | `+welcome_msg [Message]` | `+welcome_title [Title]` | `+welcome_footer [Footer]` | `+welcome_thumbnail [Image File]` | `+welcome_var`", inline=False)
64 welcembed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url)
65 await ctx.send(embed=welcembed)
66
67@bot.command(name="welcome_var")
68async def welcome_msg_variables(ctx):
69 var = "Here are the welcome embed variables. You can use them while setting the welcome embed components: \n\n`user` - *Shows only the member's name and tag. EG: X_Cuber#1840* \n\n`mention` - *Mentions the user who joined. EG: {}* \n\n`name` - *Display's member's name * \n\n`guild` - *The name of the guild the member just joined.* \n\n`membercount` - *The total number of members in the server.* \n\n\n(These will work only if you put them within a `{}` while setting the message. You also can't use these for the thumbnail.)".format(ctx.author.mention)
70 welcmsgvarembed = discord.Embed(title="Welcome Message Variables", description=var, colour=random.choice(c), timestamp=ctx.message.created_at)
71 welcmsgvarembed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url)
72 await ctx.send(embed=welcmsgvarembed)
73
74@bot.command(name="welcome_enable")
75async def welcome_enable(ctx, channel : discord.TextChannel):
76 if ctx.author.guild_permissions.manage_messages:
77 db = sqlite3.connect('welcome.sqlite')
78 cursor = db.cursor()
79 cursor.execute(f"SELECT channel_id FROM welcome WHERE guild_id = {ctx.guild.id}")
80 result = cursor.fetchone()
81
82 if result == None:
83 sql = ("INSERT INTO welcome(guild_id, channel_id) VALUES(?,?)")
84 val = (ctx.guild.id, channel.id)
85 await ctx.send(f'Welcoming channel has been set to {channel.mention}. All new members will be greeted there.')
86
87 elif result is not None:
88 sql = ("UPDATE welcome SET channel_id = ?, WHERE guild_id = ?")
89 val = (channel.id, ctx.guild.id)
90 await ctx.send(f'Welcoming channel has been updated to {channel.mention}. All new members will be greeted there.')
91 cursor.execute(sql, val)
92 db.commit()
93 cursor.close()
94 db.close()
95
96@bot.command(name="welcome_disable")
97async def welcome_disable(ctx, channel:discord.TextChannel):
98 if ctx.author.guild_permissions.manage_messages:
99 db = sqlite3.connect('welcome.sqlite')
100 cursor = db.cursor()
101 cursor.execute(f"DELETE FROM welcome WHERE channel_id = {channel.id} and guild_id = {ctx.guild.id}")
102 db.commit()
103 cursor.close()
104 db.close()
105 await ctx.send(f"Stopped welcoming members for {ctx.guild}")
106
107@bot.command(name="welcome_msg")
108async def welcome_msg(ctx, *, message):
109 if ctx.author.guild_permissions.manage_messages:
110 db = sqlite3.connect('welcome.sqlite')
111 cursor = db.cursor()
112 cursor.execute(f"SELECT msg FROM welcome WHERE guild_id = {ctx.guild.id}")
113 result = cursor.fetchone()
114
115 if result is None:
116 db = sqlite3.connect('welcome.sqlite')
117 cursor = db.cursor()
118 sql = ("INSERT INTO welcome(msg,) VALUES(?)")
119 val = (message)
120 await ctx.send(f'Welcome message has been set to: `{message}`')
121
122 elif result is not None:
123 db = sqlite3.connect('welcome.sqlite')
124 cursor = db.cursor()
125 sql = ("UPDATE welcome SET msg = ?")
126 val = (message)
127 await ctx.send(f'Welcome message has been updated to `{message}`')
128 cursor.execute(sql, val)
129 db.commit()
130 cursor.close()
131 db.close()
132
133
134@bot.command(name="welcome_footer")
135async def welcome_footer(ctx, *, footer):
136 if ctx.author.guild_permissions.manage_messages:
137 db = sqlite3.connect('welcome.sqlite')
138 cursor = db.cursor()
139 cursor.execute(f"SELECT footer FROM welcome WHERE guild_id = {ctx.guild.id}")
140 result = cursor.fetchone()
141
142 if result is None:
143 db = sqlite3.connect('welcome.sqlite')
144 cursor = db.cursor()
145 sql = ("INSERT INTO welcome(footer,) VALUES(?)")
146 val = (footer)
147 await ctx.send(f'Welcome message\'s footer has been set to: `{footer}`')
148
149 elif result is not None:
150 db = sqlite3.connect('welcome.sqlite')
151 cursor = db.cursor()
152 sql = ("UPDATE welcome SET msg = ?")
153 val = (footer)
154 await ctx.send(f'Welcome message\'s footer has been updated to `{footer}`')
155 cursor.execute(sql, val)
156 db.commit()
157 cursor.close()
158 db.close()
159
160@bot.command(name="welcome_title")
161async def welcome_footer(ctx, *, title):
162 if ctx.author.guild_permissions.manage_messages:
163 db = sqlite3.connect('welcome.sqlite')
164 cursor = db.cursor()
165 cursor.execute(f"SELECT title FROM welcome WHERE guild_id = {ctx.guild.id}")
166 result = cursor.fetchone()
167
168 if result is None:
169 db = sqlite3.connect('welcome.sqlite')
170 cursor = db.cursor()
171 sql = ("INSERT INTO welcome(title,) VALUES(?)")
172 val = (title)
173 await ctx.send(f'Welcome message\'s title has been set to: `{title}`')
174
175 elif result is not None:
176 db = sqlite3.connect('welcome.sqlite')
177 cursor = db.cursor()
178 sql = ("UPDATE welcome SET title = ?")
179 val = (title)
180 await ctx.send(f'Welcome message\'s title has been updated to `{title}`')
181 cursor.execute(sql, val)
182 db.commit()
183 cursor.close()
184 db.close()
185
186@bot.command(name="welcome_thumbnail")
187async def welcome_footer(ctx, img: discord.file):
188 if ctx.author.guild_permissions.manage_messages:
189 db = sqlite3.connect('welcome.sqlite')
190 cursor = db.cursor()
191 cursor.execute(f"SELECT icon FROM welcome WHERE guild_id = {ctx.guild.id}")
192 result = cursor.fetchone()
193
194 if result is None:
195 db = sqlite3.connect('welcome.sqlite')
196 cursor = db.cursor()
197 sql = ("INSERT INTO welcome(icon,) VALUES(?)")
198 val = (img)
199 await ctx.send(f'Welcome message\'s thumbnail has been set to: `{img}`')
200
201 elif result is not None:
202 db = sqlite3.connect('welcome.sqlite')
203 cursor = db.cursor()
204 sql = ("UPDATE welcome SET icon = ?")
205 val = (img)
206 await ctx.send(f'Welcome message\'s thumbnail has been updated to `{img}`')
207 cursor.execute(sql, val)
208 db.commit()
209 cursor.close()
210 db.close()
211
212#WELCOME FUNCTION:
213@bot.event
214async def on_member_join(member):
215 db = sqlite3.connect('welcome.sqlite')
216 cursor = db.cursor()
217 cursor.execute(f"SELECT channel_id FROM welcome WHERE guild_id = {member.guild.id}")
218 result = cursor.fetchone()
219
220 if result is None:
221 return
222 else:
223 db = sqlite3.connect('welcome.sqlite')
224 cursor1 = db.cursor()
225 cursor1.execute(f"SELECT msg, footer, icon, title FROM welcome WHERE guild_id = {member.guild.id}")
226 result1 = cursor.fetchall()
227 user = member.display_name
228 mention = member.mention
229 name = member.name
230 guild = member.guild
231 membercount = len(list(member.guild.members))
232 welcembed = discord.Embed(title=result1[4], description=str(result1[1]).format(user=user, mention=mention, name=name, guild=guild, membercount=membercount), colour=random.choice(c), timestamp=member.joined_at)
233 welcembed.set_footer(text=result1[2], icon_url=member.avatar_url)
234 welcembed.set_thumbnail(url=result1[3])
235 channel = bot.get_channel(result1[0])
236 await channel.send(embed=welcembed)
237
238bot.run(Token)