async def preview(self, ctx): """Look at the preview of your welcomer""" server = ctx.guild author = ctx.author data = r.table("welcomer").get(str(server.id)).run(durability="soft") message = data["message"] message = message.replace("{server}", server.name) message = message.replace("{user.mention}", author.mention) message = message.replace("{user.name}", author.name) message = message.replace("{user}", str(author)) message = message.replace("{server.members}", "{:,}".format(len(server.members))) message = message.replace("{server.members.prefix}", self.prefixfy(server)) message = message.replace( "{user.created.length}", dateify.get( (datetime.utcnow() - author.created_at).total_seconds())) message2 = data["message-leave"] message2 = message2.replace("{server}", server.name) message2 = message2.replace("{user.mention}", author.mention) message2 = message2.replace("{user.name}", author.name) message2 = message2.replace("{user}", str(author)) message2 = message2.replace("{server.members}", "{:,}".format(len(server.members))) message2 = message2.replace("{server.members.prefix}", self.prefixfy(server)) message2 = message2.replace( "{user.created.length}", dateify.get( (datetime.utcnow() - author.created_at).total_seconds())) s = discord.Embed(description=message, timestamp=datetime.utcnow(), colour=discord.Colour(data["embedcolour"]) if data["embedcolour"] else discord.Embed.Empty) s.set_author(name=str(author), icon_url=author.avatar_url) if data["imgwelcomertog"] and data["toggle"]: if data["embed"]: await ctx.send(embed=s, file=self.image_welcomer(author, server)) else: await ctx.send(content=message, file=self.image_welcomer(author, server)) elif data["imgwelcomertog"] and not data["toggle"]: await ctx.send(file=self.image_welcomer(author, server)) elif not data["imgwelcomertog"] and data["toggle"]: if data["embed"]: await ctx.send(embed=s) else: await ctx.send(message) else: return await ctx.send( "You have neither image welcomer or welcomer enabled :no_entry:" ) if data["leavetoggle"]: if data["embed"]: await ctx.send(embed=s) else: await ctx.send(message2)
async def on_member_remove(self, member): server = member.guild data = r.table("welcomer").get(str(server.id)).run(durability="soft") if data["dm"] == True: return if data["leavetoggle"] == False: return channel = data["channel"] channel = server.get_channel(int(channel)) if not channel: if server.system_channel: channel = server.system_channel message = data["message-leave"] if data["toggle"] == True: message = message.replace("{server}", server.name) message = message.replace("{user.mention}", member.mention) message = message.replace("{user.name}", member.name) message = message.replace("{user}", str(member)) message = message.replace("{server.members}", "{:,}".format(len(server.members))) message = message.replace("{server.members.prefix}", self.prefixfy(server)) message = message.replace( "{user.created.length}", dateify.get( (datetime.utcnow() - member.created_at).total_seconds())) if data["embed"]: s = discord.Embed(description=message, timestamp=datetime.utcnow(), colour=discord.Colour(data["embedcolour"]) if data["embedcolour"] else discord.Embed.Empty) s.set_author(name=str(member), icon_url=member.avatar_url) await self.webhook_send(channel=channel, embed=s) else: await self.webhook_send(channel=channel, content=message)
async def on_guild_remove(self, guild): try: server = guild s = discord.Embed( description= "I am now in {:,} servers and connected to {:,} users".format( len(self.bot.guilds), len(self.bot.users)), colour=0xf84b50, timestamp=datetime.utcnow()) s.set_author(name="Left Server!", icon_url=self.bot.user.avatar_url) s.add_field(name="Server Name", value=server.name) s.add_field(name="Server ID", value=server.id) s.add_field(name="Server Owner", value="{}\n{}".format(server.owner, server.owner.id)) s.add_field(name="Total members", value="{} members".format(len(server.members))) try: s.add_field(name="Stayed For", value=dateify.get( (datetime.utcnow() - server.me.joined_at).total_seconds()), inline=False) except Exception as e: pass if server.icon_url: s.set_thumbnail(url=server.icon_url) else: s.set_thumbnail( url= "https://cdn.discordapp.com/attachments/344091594972069888/396285725605363712/no_server_icon.png" ) await self.bot.get_channel(396013262514421761).send(embed=s) except Exception as e: await self.bot.get_channel(396013262514421761).send(e)
def get_welcomer_message(self, guild, member, message: str): message = message.replace("{server}", guild.name) message = message.replace("{user.mention}", member.mention) message = message.replace("{user.name}", member.name) message = message.replace("{user}", str(member)) message = message.replace("{server.members}", "{:,}".format(len(guild.members))) message = message.replace("{server.members.prefix}", self.prefixfy(guild)) message = message.replace( "{user.created.length}", dateify.get( (datetime.utcnow() - member.created_at).total_seconds())) return message