2025-09-14 18:54:56 -04:00
|
|
|
import discord
|
|
|
|
|
from discord import app_commands
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
from discord.ext.commands import Context
|
2025-10-14 17:24:41 -04:00
|
|
|
from utils.checks import is_owner_or_friend
|
2025-09-14 18:54:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Say(commands.Cog, name="say"):
|
|
|
|
|
def __init__(self, bot) -> None:
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
2025-10-14 17:24:41 -04:00
|
|
|
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False, allowed_mentions: discord.AllowedMentions = None) -> None:
|
2025-09-16 10:21:36 -04:00
|
|
|
interaction = getattr(context, "interaction", None)
|
|
|
|
|
if interaction is not None:
|
|
|
|
|
if interaction.response.is_done():
|
2025-10-14 17:24:41 -04:00
|
|
|
await interaction.followup.send(embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions)
|
2025-09-16 10:21:36 -04:00
|
|
|
else:
|
2025-10-14 17:24:41 -04:00
|
|
|
await interaction.response.send_message(embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions)
|
2025-09-16 10:21:36 -04:00
|
|
|
else:
|
2025-10-14 17:24:41 -04:00
|
|
|
await context.send(embed=embed, allowed_mentions=allowed_mentions)
|
2025-09-16 10:21:36 -04:00
|
|
|
|
2025-09-14 18:54:56 -04:00
|
|
|
@commands.hybrid_command(
|
|
|
|
|
name="say",
|
|
|
|
|
description="The bot will say anything you want.",
|
|
|
|
|
)
|
2025-09-22 10:22:06 -04:00
|
|
|
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
|
|
|
|
|
@app_commands.allowed_installs(guilds=True, users=True)
|
2025-09-14 18:54:56 -04:00
|
|
|
@app_commands.describe(message="The message that should be repeated by the bot")
|
2025-10-14 17:24:41 -04:00
|
|
|
@is_owner_or_friend()
|
2025-09-14 18:54:56 -04:00
|
|
|
async def say(self, context: Context, *, message: str) -> None:
|
|
|
|
|
"""
|
|
|
|
|
The bot will say anything you want.
|
|
|
|
|
|
|
|
|
|
:param context: The hybrid command context.
|
|
|
|
|
:param message: The message that should be repeated by the bot.
|
|
|
|
|
"""
|
2025-10-14 17:24:41 -04:00
|
|
|
if context.guild is not None:
|
|
|
|
|
self.bot.logger.info(
|
|
|
|
|
f"Say command used in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id}): {message}"
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
self.bot.logger.info(
|
|
|
|
|
f"Say command used in DMs by {context.author} (ID: {context.author.id}): {message}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
allowed_mentions = discord.AllowedMentions.none()
|
|
|
|
|
|
|
|
|
|
interaction = getattr(context, "interaction", None)
|
|
|
|
|
if interaction is not None:
|
2025-10-14 17:31:57 -04:00
|
|
|
await interaction.response.defer(ephemeral=True)
|
2025-10-14 17:24:41 -04:00
|
|
|
await context.channel.send(message, allowed_mentions=allowed_mentions)
|
2025-10-14 17:31:57 -04:00
|
|
|
try:
|
|
|
|
|
await interaction.delete_original_response()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2025-10-14 17:24:41 -04:00
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
await context.message.delete()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
await context.send(message, allowed_mentions=allowed_mentions)
|
2025-09-14 18:54:56 -04:00
|
|
|
|
|
|
|
|
@commands.hybrid_command(
|
|
|
|
|
name="embed",
|
|
|
|
|
description="The bot will say anything you want, but within embeds.",
|
|
|
|
|
)
|
2025-09-22 10:22:06 -04:00
|
|
|
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
|
|
|
|
|
@app_commands.allowed_installs(guilds=True, users=True)
|
2025-09-14 18:54:56 -04:00
|
|
|
@app_commands.describe(message="The message that should be repeated by the bot")
|
2025-10-14 17:24:41 -04:00
|
|
|
@is_owner_or_friend()
|
2025-09-14 18:54:56 -04:00
|
|
|
async def embed(self, context: Context, *, message: str) -> None:
|
|
|
|
|
"""
|
|
|
|
|
The bot will say anything you want, but using embeds.
|
|
|
|
|
|
|
|
|
|
:param context: The hybrid command context.
|
|
|
|
|
:param message: The message that should be repeated by the bot.
|
|
|
|
|
"""
|
2025-10-14 17:24:41 -04:00
|
|
|
if context.guild is not None:
|
|
|
|
|
self.bot.logger.info(
|
|
|
|
|
f"Embed command used in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id}): {message}"
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
self.bot.logger.info(
|
|
|
|
|
f"Embed command used in DMs by {context.author} (ID: {context.author.id}): {message}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
allowed_mentions = discord.AllowedMentions.none()
|
2025-09-16 10:21:36 -04:00
|
|
|
embed = discord.Embed(
|
|
|
|
|
title="Say",
|
|
|
|
|
description=message,
|
|
|
|
|
color=0x7289DA,
|
|
|
|
|
)
|
|
|
|
|
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
|
2025-10-14 17:24:41 -04:00
|
|
|
|
|
|
|
|
interaction = getattr(context, "interaction", None)
|
|
|
|
|
if interaction is not None:
|
2025-10-14 17:31:57 -04:00
|
|
|
await interaction.response.defer(ephemeral=True)
|
2025-10-14 17:24:41 -04:00
|
|
|
await context.channel.send(embed=embed, allowed_mentions=allowed_mentions)
|
2025-10-14 17:31:57 -04:00
|
|
|
try:
|
|
|
|
|
await interaction.delete_original_response()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2025-10-14 17:24:41 -04:00
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
await context.message.delete()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
await context.send(embed=embed, allowed_mentions=allowed_mentions)
|
2025-09-16 10:21:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async def cog_command_error(self, context: Context, error) -> None:
|
2025-10-14 17:24:41 -04:00
|
|
|
if isinstance(error, (commands.NotOwner, commands.CheckFailure)):
|
2025-09-16 10:21:36 -04:00
|
|
|
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
|
2025-09-14 18:54:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async def setup(bot) -> None:
|
|
|
|
|
await bot.add_cog(Say(bot))
|