mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
refactor: owner checks and embed handling in owner cogs
Removed OWNER_ID from .env and bot.py, switching to @commands.is_owner() for owner checks. Unified embed sending logic in owner cogs, improved error messages, and updated invite command to use ephemeral responses and enhanced embed formatting.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
TOKEN=YOUR_BOT_TOKEN_HERE
|
TOKEN=YOUR_BOT_TOKEN_HERE
|
||||||
PREFIX=YOUR_BOT_PREFIX_HERE
|
PREFIX=YOUR_BOT_PREFIX_HERE
|
||||||
INVITE_LINK=YOUR_BOT_INVITE_LINK_HERE
|
INVITE_LINK=YOUR_BOT_INVITE_LINK_HERE
|
||||||
OWNER_ID=YOUR_BOT_OWNER_ID_HERE
|
|
||||||
|
|
||||||
# Commands you want to disable (comma separated)
|
# Commands you want to disable (comma separated)
|
||||||
DISABLED_COGS=general.context_menus # Context Menus
|
DISABLED_COGS=general.context_menus # Context Menus
|
||||||
|
|||||||
1
bot.py
1
bot.py
@@ -112,7 +112,6 @@ class DiscordBot(commands.Bot):
|
|||||||
command_prefix=commands.when_mentioned_or(os.getenv("PREFIX")),
|
command_prefix=commands.when_mentioned_or(os.getenv("PREFIX")),
|
||||||
intents=intents,
|
intents=intents,
|
||||||
help_command=None,
|
help_command=None,
|
||||||
owner_id=int(os.getenv("OWNER_ID")) if os.getenv("OWNER_ID") else None,
|
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
This creates custom bot variables so that we can access these variables in cogs more easily.
|
This creates custom bot variables so that we can access these variables in cogs more easily.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class CogManagement(commands.Cog, name="cog_management"):
|
|||||||
else:
|
else:
|
||||||
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
|
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
|
||||||
else:
|
else:
|
||||||
await self.send_embed(context, embed)
|
await context.send(embed=embed)
|
||||||
|
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="load",
|
name="load",
|
||||||
@@ -109,7 +109,7 @@ class CogManagement(commands.Cog, name="cog_management"):
|
|||||||
async def cog_command_error(self, context: Context, error) -> None:
|
async def cog_command_error(self, context: Context, error) -> None:
|
||||||
if isinstance(error, commands.NotOwner):
|
if isinstance(error, commands.NotOwner):
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Error",
|
title="Permission Denied",
|
||||||
description="You are not the owner of the bot!",
|
description="You are not the owner of the bot!",
|
||||||
color=0xE02B2B
|
color=0xE02B2B
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,10 +8,21 @@ class Invite(commands.Cog, name="invite"):
|
|||||||
def __init__(self, bot) -> None:
|
def __init__(self, bot) -> None:
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if interaction.response.is_done():
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
|
||||||
|
else:
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed)
|
||||||
|
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="invite",
|
name="invite",
|
||||||
description="Get the invite link of the bot to be able to invite it.",
|
description="Get the invite link of the bot to be able to invite it.",
|
||||||
)
|
)
|
||||||
|
@commands.is_owner()
|
||||||
async def invite(self, context: Context) -> None:
|
async def invite(self, context: Context) -> None:
|
||||||
"""
|
"""
|
||||||
Get the invite link of the bot to be able to invite it.
|
Get the invite link of the bot to be able to invite it.
|
||||||
@@ -27,14 +38,26 @@ class Invite(commands.Cog, name="invite"):
|
|||||||
f"https://discord.com/api/oauth2/authorize?client_id={client.id}"
|
f"https://discord.com/api/oauth2/authorize?client_id={client.id}"
|
||||||
f"&scope=bot%20applications.commands&permissions={permissions}"
|
f"&scope=bot%20applications.commands&permissions={permissions}"
|
||||||
)
|
)
|
||||||
embed = discord.Embed(description=f"Invite me by clicking [here]({invite_url}).", color=0x7289DA)
|
embed = discord.Embed(title="Invite", description=f"Invite me by clicking [here]({invite_url}).", color=0x7289DA)
|
||||||
embed.set_author(name="Invite Me", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await context.author.send(embed=embed)
|
await context.author.send(embed=embed)
|
||||||
await context.send("I sent you a private message!")
|
await self.send_embed(context, discord.Embed(description="I sent you a private message!", color=0x7289DA), ephemeral=True)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
await context.send(embed=embed)
|
await self.send_embed(context, embed, ephemeral=True)
|
||||||
|
|
||||||
|
async def cog_command_error(self, context: Context, error) -> None:
|
||||||
|
if isinstance(error, commands.NotOwner):
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Permission Denied",
|
||||||
|
description="You are not the owner of this bot.",
|
||||||
|
color=0xE02B2B
|
||||||
|
)
|
||||||
|
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
|
||||||
|
await self.send_embed(context, embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
raise error
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot) -> None:
|
async def setup(bot) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user