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

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