welcome_msg.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import discord
  2. from discord.ext import commands
  3. from discord.commands import Option
  4. from discord.commands import slash_command
  5. import configparser
  6. import time
  7. class welcome_msg(commands.Cog):
  8. def __init__(self, bot: discord.Bot):
  9. self.bot = bot
  10. def _load_config(self):
  11. config = configparser.ConfigParser()
  12. configFilePath = r'config.cfg'
  13. config.read(configFilePath)
  14. return config
  15. @commands.Cog.listener()
  16. async def on_member_join(self, member):
  17. config = self._load_config(self)
  18. enable_welcome_message = config.getboolean("Welcome Message","enable_welcome_message")
  19. if not enable_welcome_message:
  20. return
  21. welcome_channel_id = config.getint("Welcome Message","welcome_channel_id")
  22. welcome_channel = self.bot.get_channel(welcome_channel_id)
  23. if welcome_channel is None:
  24. print(f"Welcome channel with ID {welcome_channel_id} not found.")
  25. return
  26. embed = discord.Embed(
  27. title="VicePD",
  28. description=f"Willkommen {member.mention}, auf **VicePD**! \n\n Bitte lese dir das <#1442279753707946215> durch. Die Einhaltung der Regeln stellt sicher, dass der Server ein freundlicher und unterhaltsamer Ort für alle ist und bleibt. \n\n Viel Spaß auf VicePD!",
  29. color=discord.Color.grey(),
  30. timestamp=discord.utils.utcnow()
  31. )
  32. embed.set_image(url="https://i.imgur.com/iu1VyKZ.png")
  33. embed.set_footer(text=f"Member ID: {member.id}")
  34. self.bot.loop.create_task(welcome_channel.send(embed=embed))
  35. #await welcome_channel.send(embed=embed)
  36. def setup(bot: discord.Bot):
  37. bot.add_cog(welcome_msg(bot))