You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5KB

  1. import discord
  2. from config.server_config import ServerConfig
  3. class JoinLeave():
  4. def __init__(self, Bot):
  5. self.bot = Bot
  6. self.con = ServerConfig()
  7. self.servers = self.con.servers
  8. async def on_member_join(self, member):
  9. """
  10. Greets users when they join a server.
  11. """
  12. self.con.load_config()
  13. if not self.servers[str(member.server.id)]["greets"]["enabled"]:
  14. return
  15. if self.servers[str(member.server.id)]["greets"]["custom-message"]:
  16. message = self.servers[str(member.server.id)]["greets"]["custom-message"]
  17. else:
  18. message = self.servers[str(member.server.id)]["greets"]["default-message"]
  19. em = discord.Embed(
  20. title="Welcome to {}!".format(member.server),
  21. description='Hey {}! Welcome to **{}**! {}'.format(member.mention, member.server, message),
  22. colour=0xDEADBF)
  23. em.set_thumbnail(url=member.avatar_url)
  24. channel = self.bot.get_channel(self.servers[str(member.server.id)]["greets"]["welcome-channel"])
  25. return await channel.send(embed=em)
  26. async def on_member_remove(self, member):
  27. """
  28. The same but the opposite
  29. """
  30. self.con.load_config()
  31. channel = self.servers[str(member.server.id)]["goodbyes"]["goodbye-channel"]
  32. if not self.servers[str(member.server.id)]["goodbyes"]["enabled"]:
  33. return
  34. else:
  35. channel = self.bot.get_channel(channel)
  36. return await channel.send(embed=discord.Embed(
  37. description="{}#{} has left or been beaned.".format(member.name, member.discriminator), colour=0xDEADBF))
  38. def setup(Bot):
  39. Bot.add_cog(JoinLeave(Bot))