feat: add welcomer cog for greeting new members

Introduces a simple cog that welcomes new users via customizable messages in designated channels, enhancing community engagement.

Handles channel selection with fallbacks and includes error resilience for permission issues.
This commit is contained in:
2025-09-11 17:24:56 -04:00
parent eec57c7e23
commit 8a7621836f
4 changed files with 63 additions and 0 deletions

9
welcomer/README.md Normal file
View File

@@ -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).

0
welcomer/__init__.py Normal file
View File

14
welcomer/info.json Normal file
View File

@@ -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."
}

40
welcomer/welcomer.py Normal file
View File

@@ -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))