commit
Add a welcome message
diff --git a/.env.example b/.env.example
index a8b5c96..b5586c3 100644
--- a/.env.example
+++ b/.env.example
@@ -2,4 +2,5 @@ BOT_TOKEN=
GUILD_ID=
JOIN_ROLE_ID=
BOT_JOIN_ROLE_ID=
-DATABASE_DIR=./data
\ No newline at end of file
+DATABASE_DIR=./data
+WELCOME_CHANNEL_ID=
\ No newline at end of file
diff --git a/columbina/config.py b/columbina/config.py
index be05cbc..20b9569 100644
--- a/columbina/config.py
+++ b/columbina/config.py
@@ -40,6 +40,7 @@ def readId(raw: str | None) -> int | None:
guildId = readId(os.getenv("GUILD_ID"))
joinRoleID = readId(os.getenv("JOIN_ROLE_ID"))
botRoleID = readId(os.getenv("BOT_JOIN_ROLE_ID"))
+welcomeChannelId = readId(os.getenv("WELCOME_CHANNEL_ID"))
def resolveDir(raw: str | None, fallback: Path) -> Path:
"""A configured directory, read relative to the repo rather than the cwd.
diff --git a/commands/events.py b/commands/events.py
index 2a6f72f..d005718 100644
--- a/commands/events.py
+++ b/commands/events.py
@@ -1,4 +1,5 @@
import discord
+from discord import ui as a
from discord.ext import commands
from columbina import client, config
@@ -8,7 +9,18 @@ class Events(commands.Cog):
self.bot = bot
@commands.Cog.listener()
- async def on_member_join(self, member: discord.Member) -> None:
+ async def on_member_join(self, member: discord.Member) -> None:
+ try:
+ await self.memberRole(member)
+ except discord.Forbidden or discord.HTTPException as e:
+ print(f"[roles] There was an error {e}")
+
+ try:
+ await self.welcomeMessage(member)
+ except discord.Forbidden or discord.HTTPException as f:
+ print(f"[welcome] There was an error {f}")
+
+ async def memberRole(self, member: discord.Member) -> None:
role = member.guild.get_role(config.joinRoleID)
botRole = member.guild.get_role(config.botRoleID)
@@ -24,6 +36,29 @@ class Events(commands.Cog):
return
await member.add_roles(role)
return
+
+ async def welcomeMessage(self, member: discord.Member) -> None:
+ channel = self.bot.get_channel(config.welcomeChannelId) or None
+ if channel is None:
+ print("[welcome] welcomeChannelId is not set!")
+ return
+
+ component = a.LayoutView ().add_item(
+ a.Container(
+ a.Section(
+ a.TextDisplay(content=f"# Welcome to Doughmination\n{member.mention}"),
+ accessory=a.Thumbnail(media=member.display_avatar.url),
+ ),
+ a.ActionRow(
+ a.Button(style=discord.ButtonStyle.link, label="Read the rules", url="https://discord.com/channels/1522105591739187262/1524763481948295270"),
+ a.Button(style=discord.ButtonStyle.blurple, label="Placeholder", disabled=True)
+ ),
+ a.TextDisplay(content="-# Any questions, feel free to ping <@1025770042245251122>"),
+ accent_color=discord.Color.orange()
+ )
+ )
+ await channel.send(view=component, allowed_mentions=discord.AllowedMentions.none())
+ return
-async def setup(bot: Bot) -> None:
+async def setup(bot: client.Bot) -> None:
await bot.add_cog(Events(bot))
\ No newline at end of file