import discord from redbot.core import commands, Config from redbot.core.bot import Red from typing import Literal class Welcomer(commands.Cog): """ A configurable cog to automatically welcome new users with multiple modes. """ def __init__(self, bot: Red): self.bot = bot self.config = Config.get_conf(self, identifier=1234567890, force_registration=True) default_guild = { "welcome_channel": None, "welcome_message": "Welcome to the server, {user.mention}!", "enabled": False, "welcome_mode": "normal" # 'normal' or 'solstira' } self.config.register_guild(**default_guild) @commands.Cog.listener() async def on_member_join(self, member: discord.Member): guild = member.guild if not await self.config.guild(guild).enabled(): return mode = await self.config.guild(guild).welcome_mode() if mode == "solstira": # Hardcoded Solstira welcome event channel_id = 1409965732669948024 else: # Normal mode channel_id = await self.config.guild(guild).welcome_channel() if not channel_id: return channel = guild.get_channel(channel_id) if not isinstance(channel, discord.TextChannel): return if not channel.permissions_for(guild.me).send_messages: return if mode == "solstira": content = ( f"{member.mention}\n" f"- `guide` \n" f"- `roles` <@&1409937150>\n" f"()\n" f"- `psa` ()" ) embed = discord.Embed(description="--", color=0x8b9ed7) try: await channel.send(content, embed=embed) except discord.HTTPException: pass else: # Normal mode message_template = await self.config.guild(guild).welcome_message() formatted_message = message_template.format( user=member, user_mention=member.mention, user_name=member.name, server_name=guild.name ) try: await channel.send(formatted_message) except discord.HTTPException: pass @commands.group(aliases=["wset"]) # type: ignore @commands.guild_only() @commands.admin_or_permissions(manage_guild=True) async def welcomeset(self, ctx: commands.Context): """Commands for configuring the welcome system.""" pass @welcomeset.command(name="mode") async def set_welcome_mode(self, ctx: commands.Context, mode: Literal["normal", "solstira"]): """Set the welcome mode for this server. Modes: - `normal`: A simple, configurable welcome message. - `solstira`: The special, complex welcome event. """ if not ctx.guild: return await self.config.guild(ctx.guild).welcome_mode.set(mode.lower()) await ctx.send(f"Welcome mode has been set to **{mode.lower()}**.") @welcomeset.command(name="channel") async def set_welcome_channel(self, ctx: commands.Context, channel: discord.TextChannel): """(Normal Mode) Set the channel for welcome messages.""" if not ctx.guild: return await self.config.guild(ctx.guild).welcome_channel.set(channel.id) await ctx.send(f"Welcome channel set to {channel.mention}") @welcomeset.command(name="message") async def set_welcome_message(self, ctx: commands.Context, *, message: str): """(Normal Mode) Set the welcome message. Use placeholders like {user.mention}.""" if not ctx.guild: return await self.config.guild(ctx.guild).welcome_message.set(message) await ctx.send("Welcome message updated.") @welcomeset.command(name="toggle") async def toggle_welcome(self, ctx: commands.Context): """Toggle the welcome system on or off.""" if not ctx.guild: return current_status = await self.config.guild(ctx.guild).enabled() new_status = not current_status await self.config.guild(ctx.guild).enabled.set(new_status) status_text = "enabled" if new_status else "disabled" await ctx.send(f"Welcome system has been {status_text}.") async def setup(bot: Red): await bot.add_cog(Welcomer(bot))