Refactor welcome message handling in the Autorole cog to enhance user experience. Implement dynamic embed creation for guild join events, including updated branding and links to the dashboard and support server. Improve error handling for direct messages and audit log access.
This commit is contained in:
@@ -12,40 +12,107 @@
|
|||||||
# ╚══════════════════════════════════════════════════════════════════╝
|
# ╚══════════════════════════════════════════════════════════════════╝
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from utils.emoji import ARROWRED, ZMODULE
|
|
||||||
from discord.utils import *
|
|
||||||
from core import Axiom, Cog
|
from core import Axiom, Cog
|
||||||
from utils.Tools import *
|
from utils.config import BotName, BRAND_NAME, DISCORD_CLIENT_ID, serverLink
|
||||||
from utils.config import BotName, serverLink
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ui import Button, View
|
from discord.ui import Button, View
|
||||||
|
|
||||||
|
# HexaHost brand accent (matches dashboard primary/accent)
|
||||||
|
EMBED_COLOR = 0xA348FF
|
||||||
|
DASHBOARD_URL = "https://bot.hexahost.de"
|
||||||
|
|
||||||
|
|
||||||
class Autorole(Cog):
|
class Autorole(Cog):
|
||||||
def __init__(self, bot: Axiom):
|
def __init__(self, bot: Axiom):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
def _invite_url(self) -> str | None:
|
||||||
|
client_id = DISCORD_CLIENT_ID or (str(self.bot.user.id) if self.bot.user else "")
|
||||||
|
if not client_id:
|
||||||
|
return None
|
||||||
|
return (
|
||||||
|
f"https://discord.com/oauth2/authorize?client_id={client_id}"
|
||||||
|
f"&permissions=8&scope=bot%20applications.commands"
|
||||||
|
)
|
||||||
|
|
||||||
|
def _welcome_embed(self, guild: discord.Guild, adder: discord.abc.User) -> discord.Embed:
|
||||||
|
bot_avatar = guild.me.display_avatar.url if guild.me else (
|
||||||
|
self.bot.user.display_avatar.url if self.bot.user else None
|
||||||
|
)
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title=f"Thanks for adding {BotName}",
|
||||||
|
description=(
|
||||||
|
f"Hey {adder.mention}, **{BotName}** is now in **{guild.name}**.\n\n"
|
||||||
|
"Here's everything you need to get started:"
|
||||||
|
),
|
||||||
|
color=EMBED_COLOR,
|
||||||
|
)
|
||||||
|
|
||||||
|
if bot_avatar:
|
||||||
|
embed.set_author(name=BotName, icon_url=bot_avatar)
|
||||||
|
embed.set_thumbnail(url=bot_avatar)
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name="Prefix",
|
||||||
|
value="Default prefix is `>`\nExample: `>help`",
|
||||||
|
inline=True,
|
||||||
|
)
|
||||||
|
embed.add_field(
|
||||||
|
name="Slash commands",
|
||||||
|
value="Type `/` in your server to browse available commands.",
|
||||||
|
inline=True,
|
||||||
|
)
|
||||||
|
embed.add_field(
|
||||||
|
name="Dashboard",
|
||||||
|
value=f"Configure modules online at **[bot.hexahost.de]({DASHBOARD_URL})**",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
embed.add_field(
|
||||||
|
name="Need help?",
|
||||||
|
value=f"Join our **[Support Server]({serverLink})** for guides, FAQ and assistance.",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_footer(text=f"Powered by HexaHost · {BRAND_NAME}")
|
||||||
|
return embed
|
||||||
|
|
||||||
|
def _welcome_view(self) -> View:
|
||||||
|
view = View()
|
||||||
|
view.add_item(
|
||||||
|
Button(label="Open Dashboard", style=discord.ButtonStyle.link, url=DASHBOARD_URL)
|
||||||
|
)
|
||||||
|
view.add_item(
|
||||||
|
Button(label="Support Server", style=discord.ButtonStyle.link, url=serverLink)
|
||||||
|
)
|
||||||
|
invite = self._invite_url()
|
||||||
|
if invite:
|
||||||
|
view.add_item(
|
||||||
|
Button(label="Add to another server", style=discord.ButtonStyle.link, url=invite)
|
||||||
|
)
|
||||||
|
return view
|
||||||
|
|
||||||
@commands.Cog.listener(name="on_guild_join")
|
@commands.Cog.listener(name="on_guild_join")
|
||||||
async def send_msg_to_adder(self, guild: discord.Guild):
|
async def send_msg_to_adder(self, guild: discord.Guild):
|
||||||
async for entry in guild.audit_logs(limit=3):
|
try:
|
||||||
if entry.action == discord.AuditLogAction.bot_add:
|
async for entry in guild.audit_logs(limit=5, action=discord.AuditLogAction.bot_add):
|
||||||
embed = discord.Embed(
|
if entry.target is None or entry.user is None:
|
||||||
description=f"{ZMODULE} **Thanks for adding me.**\n\n{ARROWRED} My default prefix is `>`\n{ARROWRED}> Use the `>help` command to see a list of commands\n{ARROWRED} For detailed guides, FAQ and information, visit our **[Support Server](https://discord.gg/hexahost)**",
|
continue
|
||||||
color=0xFF0000
|
if entry.target.id != self.bot.user.id:
|
||||||
)
|
continue
|
||||||
embed.set_thumbnail(url=entry.user.avatar.url if entry.user.avatar else entry.user.default_avatar.url)
|
|
||||||
embed.set_author(name=f"{guild.name}", icon_url=guild.me.display_avatar.url)
|
|
||||||
|
|
||||||
website_button = Button(label='Website', style=discord.ButtonStyle.link, url='https://.vercel.app')
|
embed = self._welcome_embed(guild, entry.user)
|
||||||
support_button = Button(label='Support', style=discord.ButtonStyle.link, url='https://discord.gg/hexahost')
|
view = self._welcome_view()
|
||||||
vote_button = Button(label='Vote for Me', style=discord.ButtonStyle.link, url=f'https://top.gg/bot/{self.bot.user.id}/vote')
|
|
||||||
view = View()
|
|
||||||
view.add_item(support_button)
|
|
||||||
#view.add_item(website_button)
|
|
||||||
#view.add_item(vote_button)
|
|
||||||
if guild.icon:
|
|
||||||
embed.set_author(name=guild.name, icon_url=guild.icon.url)
|
|
||||||
try:
|
try:
|
||||||
await entry.user.send(embed=embed, view=view)
|
await entry.user.send(embed=embed, view=view)
|
||||||
|
except discord.Forbidden:
|
||||||
|
# User has DMs closed — ignore silently
|
||||||
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(f"Welcome DM failed: {e}")
|
||||||
|
break
|
||||||
|
except discord.Forbidden:
|
||||||
|
# Missing View Audit Log permission
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Welcome DM (audit log) failed: {e}")
|
||||||
|
|||||||
@@ -99,25 +99,37 @@ Threads : {len(guild.threads)}
|
|||||||
await guild.chunk()
|
await guild.chunk()
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
description=f"{ARROWRED} Prefix For This Server is `>`\n{ARROWRED} Get Started with `>help`\n{ARROWRED} For detailed guides, FAQ & information, visit our **[Support Server](https://discord.gg/hexahost)**",
|
title=f"{BRAND_NAME} joined the server",
|
||||||
color=0xFF0000,
|
description=(
|
||||||
|
f"**{BRAND_NAME}** is ready to use.\n\n"
|
||||||
|
f"▸ Default prefix: `>`\n"
|
||||||
|
f"▸ Get started with `>help` or type `/`\n"
|
||||||
|
f"▸ Dashboard: **[bot.hexahost.de](https://bot.hexahost.de)**\n"
|
||||||
|
f"▸ Support: **[discord.gg/hexahost](https://discord.gg/hexahost)**"
|
||||||
|
),
|
||||||
|
color=0xA348FF,
|
||||||
)
|
)
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name="Thanks for adding me!", icon_url=guild.me.display_avatar.url
|
name=BRAND_NAME,
|
||||||
|
icon_url=guild.me.display_avatar.url if guild.me else None,
|
||||||
)
|
)
|
||||||
embed.set_footer(
|
embed.set_footer(text=f"Powered by HexaHost · {BRAND_NAME}")
|
||||||
text=f"Powered by {BRAND_NAME}™",
|
if guild.me:
|
||||||
)
|
embed.set_thumbnail(url=guild.me.display_avatar.url)
|
||||||
if guild.icon:
|
|
||||||
embed.set_thumbnail(url=guild.icon.url)
|
|
||||||
|
|
||||||
support = Button(
|
support = Button(
|
||||||
label="Support",
|
label="Support Server",
|
||||||
style=discord.ButtonStyle.link,
|
style=discord.ButtonStyle.link,
|
||||||
url=f"https://discord.gg/hexahost",
|
url="https://discord.gg/hexahost",
|
||||||
|
)
|
||||||
|
dashboard = Button(
|
||||||
|
label="Open Dashboard",
|
||||||
|
style=discord.ButtonStyle.link,
|
||||||
|
url="https://bot.hexahost.de",
|
||||||
)
|
)
|
||||||
|
|
||||||
view = View()
|
view = View()
|
||||||
|
view.add_item(dashboard)
|
||||||
view.add_item(support)
|
view.add_item(support)
|
||||||
channel = discord.utils.get(guild.text_channels, name="general")
|
channel = discord.utils.get(guild.text_channels, name="general")
|
||||||
if not channel:
|
if not channel:
|
||||||
|
|||||||
Reference in New Issue
Block a user