async def leave_channel(self, ctx, *, channel: discord.TextChannel): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["leave_channel"] = str(channel.id) await ctx.send( f"This server's leave channel has been set to {channel.mention}")
async def on_member_join(member): guild: discord.Guild = member.guild channels = guild.channels if str(guild.id) not in Data.server_data: Data.server_data[str(guild.id)] = Data.create_new_data() data = Data.server_data[str(guild.id)] print(f"{member} has joined {guild} server...") join_role = guild.get_role(data["join_role"]) if join_role is not None: await member.add_roles(join_role) # Welcome Message if data["welcome_msg"] is None: server_wlcm_msg = f"Welcome, {member.mention}, to the Official **{guild.name}** Server" else: server_wlcm_msg = data["welcome_msg"] server_wlcm_msg = server_wlcm_msg.replace("[mention]", f"{member.mention}") for channel in channels: if str(channel).find("welcome") != -1: await channel.send(server_wlcm_msg) break
async def prefix(self, ctx, prefix="s!"): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["prefix"] = prefix await ctx.send(f"The prefix for this server has been set to `{prefix}`" )
async def afk(self, ctx, *, reason=None): embed = discord.Embed(color=self.theme_color, timestamp=datetime.datetime.utcnow()) if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() data = Data.server_data[str(ctx.guild.id)] # Error messages if reason is None: embed.add_field(name='Warning', value='Please specify a reason.') for afk_user_entry in data["afks"]: afk_user_id = str(afk_user_entry["user"]) if str(ctx.author.id) == afk_user_id: embed.add_field(name='Warning', value='You are already AFK.') break if len(embed.fields) == 0: afk_entry = {"user": str(ctx.author.id), "reason": reason} Data.server_data[str(ctx.guild.id)]["afks"].append(afk_entry) await ctx.send(f"**{ctx.author}** is now AFK because **{reason}**") return await ctx.send(embed=embed)
async def on_member_remove(member): guild = member.guild channels = guild.channels if str(guild.id) not in Data.server_data: Data.server_data[str(guild.id)] = Data.create_new_data() data = Data.server_data[str(guild.id)] print(f"{member} has left the {guild.name}...") # Leave Message if data["leave_msg"] is None: server_leave_msg = f"Goodbye, **{str(member)}**, thank you for staying at **{guild.name}** Server" else: server_leave_msg = data["leave_msg"] server_leave_msg = server_leave_msg.replace("[member]", f"{member}") # Leave Channel lv_channel = None if data["leave_channel"] is None: for channel in channels: if str(channel).find("bye") != -1 or str(channel).find( "leave") != -1: lv_channel = channel break else: lv_channel = guild.get_channel(int(data["leave_channel"])) try: await lv_channel.send(server_leave_msg) except AttributeError: print("DEBUG: No leave channel has been set or found.")
async def whitelisturl(ctx, url: str = None): if url is None: ctx.send("Insufficient Arguments") else: if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["urls"].append(url) await ctx.send(f"Added `{url}` to AutoMod URL whitelist.")
async def whitelistuser(ctx, user: discord.User = None): if user is None: ctx.send("Insufficient Arguments") else: if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["users"].append(str(user.id)) await ctx.send(f"Added {user.mention} to AutoMod user whitelist.")
async def welcome_message(self, ctx, *, msg: str = ""): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["welcome_msg"] = msg if len(msg.strip()) == 0: await ctx.send("This server's welcome message has been disabled") else: await ctx.send( f"This server's welcome message has been set to ```{msg}```")
async def leave_message(self, ctx, *, msg: str = None): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["leave_msg"] = msg if msg is None: await ctx.send("This server's leave message has been disabled") else: await ctx.send( f"This server's leave message has been set to ```{msg}```")
async def whitelistchannel(ctx, channel: discord.TextChannel = None): if channel is None: ctx.send("Insufficient Arguments") else: if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["channels"].append(str(channel.id)) await ctx.send(f"Added {channel.mention} to AutoMod Channel whitelist." )
async def on_message(message: discord.Message): author: discord.Member = message.author channel: discord.TextChannel = message.channel guild: discord.Guild = message.guild # print(str(author), ": ", message.content) await bot.process_commands(message) if str(guild.id) not in Data.server_data: Data.server_data[str(guild.id)] = Data.create_new_data() data = Data.server_data[str(guild.id)] if data["pay_respects"] and message.content.strip().lower() == "f": await channel.send( f"**{author.display_name}** has paid their respects...") if data["active"] and str(author.id) not in data["users"]: if not str(channel.id) in data["channels"]: perms = author.permissions_in(channel) if not perms.administrator: if "http://" in message.content or "https://" in message.content: if len(data["urls"]) > 0: for url in data["urls"]: if not url in message.content: await channel.purge(limit=1) await channel.send( f"{author.mention}, you are not allowed to send links in this channel." ) else: await channel.purge(limit=1) await channel.send( f"{author.mention}, you are not allowed to send links in this channel." ) elif len(message.attachments) > 0: await channel.purge(limit=1) await channel.send( f"{author.mention}, you are not allowed to send attachments in this channel." )
async def on_member_join(member): guild: discord.Guild = member.guild channels = guild.channels if str(guild.id) not in Data.server_data: Data.server_data[str(guild.id)] = Data.create_new_data() data = Data.server_data[str(guild.id)] print(f"{member} has joined {guild} server...") join_role = guild.get_role(data["join_role"]) if join_role is not None: await member.add_roles(join_role) # Welcome Message if data["welcome_msg"] is None: server_wlcm_msg = f"Welcome, {member.mention}, to the Official **{guild.name}** Server" else: server_wlcm_msg = data["welcome_msg"] server_wlcm_msg = server_wlcm_msg.replace("[mention]", f"{member.mention}") # Welcome Channel wel_channel = None if data["welcome_channel"] is None: for channel in channels: if str(channel).find("welcome") != -1: wel_channel = channel break else: wel_channel = guild.get_channel(int(data["welcome_channel"])) try: await wel_channel.send(server_wlcm_msg) except AttributeError: print("DEBUG: No welcome channel has been set or found.")
async def join_role(self, ctx, *, role: discord.Role): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["join_role"] = role.id await ctx.send(f"This server's join role has been set to **{role}**")
async def disablerespects(self, ctx): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["pay_respects"] = False await ctx.send("Respects have been disabled!")
def get_prefix(client, message): if str(message.guild.id) not in Data.server_data: Data.server_data[str(message.guild.id)] = Data.create_new_data() data = Data.server_data[str(message.guild.id)] return data["prefix"]
async def on_message(message: discord.Message): global previous_msg_sender_id if message.author.bot: return author: discord.Member = message.author channel: discord.TextChannel = message.channel guild: discord.Guild = message.guild # print(str(author), ": ", message.content) await bot.process_commands(message) if str(guild.id) not in Data.server_data: Data.server_data[str(guild.id)] = Data.create_new_data() data = Data.server_data[str(guild.id)] if message.content.replace('!', '') == bot.user.mention: pre = data["prefix"] await channel.send(f"The prefix in this server is `{pre}`") for afk_user_entry in data["afks"]: afk_user_id = int(afk_user_entry["user"]) afk_reason = afk_user_entry["reason"] afk_user = guild.get_member(afk_user_id) if afk_user.id == author.id and afk_user_id == previous_msg_sender_id: Data.server_data[str(guild.id)]["afks"].remove(afk_user_entry) await channel.send(f"**{afk_user}** is no longer AFK.") elif afk_user in message.mentions: await channel.send( f"**{afk_user}** is currently AFK because **{afk_reason}**.") if data["pay_respects"] and message.content.strip().lower() == "f": await channel.send( f"**{author.display_name}** has paid their respects...") if data["active"] and str(author.id) not in data["users"]: if not str(channel.id) in data["channels"]: perms = author.permissions_in(channel) if not perms.administrator: if "http://" in message.content or "https://" in message.content: if len(data["urls"]) > 0: for url in data["urls"]: if not url in message.content: await channel.purge(limit=1) msg1 = await channel.send( f"{author.mention}, you are not allowed to send links in this channel." ) await asyncio.sleep(2) await msg1.delete() else: await channel.purge(limit=1) msg2 = await channel.send( f"{author.mention}, you are not allowed to send links in this channel." ) await asyncio.sleep(3) await msg2.delete() elif len(message.attachments) > 0: await channel.purge(limit=1) msg3 = await channel.send( f"{author.mention}, you are not allowed to send attachments in this channel." ) await asyncio.sleep(3) await msg3.delete() previous_msg_sender_id = author.id
async def remove_welcome(ctx, *, channel): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["leave_channel"] = channel await ctx.send("This server's leave channel has been Removed")
async def stopautomod(ctx): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["active"] = False await ctx.send("Automod is now inactive in your server...")
async def activateautomod(self, ctx): if str(ctx.guild.id) not in Data.server_data: Data.server_data[str(ctx.guild.id)] = Data.create_new_data() Data.server_data[str(ctx.guild.id)]["active"] = True await ctx.send("Automod is now active in your server...")