diff --git a/welcomer/README.md b/welcomer/README.md new file mode 100644 index 0000000..5b7409e --- /dev/null +++ b/welcomer/README.md @@ -0,0 +1,9 @@ +# Welcomer Cog + +A simple cog to welcome new users to a server with a customizable message. + +**Features:** +- Greets new members in a designated channel. +- Uses custom formatting provided by the server admin. + +For full documentation, please visit the [repository wiki](https://git.kitsunic.org/kitsunicWorks/unstable-cogs/wiki). \ No newline at end of file diff --git a/welcomer/__init__.py b/welcomer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/welcomer/info.json b/welcomer/info.json new file mode 100644 index 0000000..416ae1d --- /dev/null +++ b/welcomer/info.json @@ -0,0 +1,14 @@ +{ + "author": [ "unstableCogs" ], + "install_msg": "Thank you for installing the Welcomer cog!", + "name": "Welcomer", + "short": "A simple cog to welcome new users.", + "description": "Greets new members in a designated channel with a customizable message. This cog is part of the Unified Bot Suite.", + "tags": [ + "welcome", + "utility", + "greeting" + ], + "requirements": [], + "end_user_data_statement": "This cog does not persistently store any end user data." +} \ No newline at end of file diff --git a/welcomer/welcomer.py b/welcomer/welcomer.py new file mode 100644 index 0000000..5b0c6ee --- /dev/null +++ b/welcomer/welcomer.py @@ -0,0 +1,40 @@ +# welcomer.py + +from redbot.core import commands +from redbot.core.bot import Red +import discord + +class Welcomer(commands.Cog): + """A simple cog to welcome new users.""" + + def __init__(self, bot: Red): + self.bot = bot + + @commands.Cog.listener() + async def on_member_join(self, member): + """Greets a new member when they join the server.""" + + guild = member.guild + while True: + # Try to find a channel named 'welcome' + channel = discord.utils.get(guild.text_channels, name='welcome') + if channel is None: + # If not found, try to find a channel named 'general' + channel = discord.utils.get(guild.text_channels, name='general') + if channel is None: + # If still not found, use the first text channel available + if guild.text_channels: + channel = guild.text_channels[0] + else: + # If no text channels exist, exit the function + return + try: + await channel.send(f"Welcome to the server, {member.mention}!") + break # Exit the loop after successfully sending the message + except discord.Forbidden: + # If we don't have permission to send messages in this channel, try again + continue + +# This function allows Red to load the cog +async def setup(bot: Red): + await bot.add_cog(Welcomer(bot)) \ No newline at end of file