fixed earrape effect, ffmpeg variables limited. /playfile now supports file attachments creating a hybrid command
This commit is contained in:
@@ -141,37 +141,54 @@ class music(commands.Cog):
|
||||
await queue.play(ctx)
|
||||
|
||||
|
||||
@commands.command(
|
||||
help="Upload and play an audio file (MP3, MP4, WAV, etc.)",
|
||||
@commands.hybrid_command(
|
||||
name="playfile",
|
||||
description="Upload and play an audio file (MP3, MP4, WAV, etc.)",
|
||||
aliases=['pf', 'file'])
|
||||
async def playfile(self, ctx: Context):
|
||||
@app_commands.describe(file="Audio file to play (MP3, MP4, WAV, OGG, FLAC, etc.)")
|
||||
async def playfile(self, ctx: Context, file: discord.Attachment = None):
|
||||
"""Play an uploaded audio file from Discord attachment"""
|
||||
if ctx.guild is None:
|
||||
await ctx.send("❌ This command must be used in a server!")
|
||||
return
|
||||
|
||||
# Check if there's an attachment
|
||||
if not ctx.message.attachments:
|
||||
await ctx.send(
|
||||
"❌ No file attached! Please upload an audio file with your message.\n"
|
||||
"**Supported formats:** MP3, MP4, WAV, OGG, FLAC, M4A, WEBM, AAC, OPUS"
|
||||
)
|
||||
await ctx.send("❌ This command must be used in a server!", ephemeral=True)
|
||||
return
|
||||
|
||||
server = ctx.guild.id
|
||||
attachment = ctx.message.attachments[0]
|
||||
|
||||
# Handle both slash command (file parameter) and prefix command (attachment)
|
||||
if file is not None:
|
||||
# Slash command with file parameter
|
||||
attachment = file
|
||||
elif ctx.message and ctx.message.attachments:
|
||||
# Prefix command with attached file
|
||||
attachment = ctx.message.attachments[0]
|
||||
else:
|
||||
# No file provided
|
||||
await ctx.send(
|
||||
"❌ No file attached! Please upload an audio file.\n"
|
||||
"**Supported formats:** MP3, MP4, WAV, OGG, FLAC, M4A, WEBM, AAC, OPUS",
|
||||
ephemeral=True if ctx.interaction else False
|
||||
)
|
||||
return
|
||||
|
||||
# Validate file extension
|
||||
audio_extensions = ('.mp3', '.mp4', '.wav', '.ogg', '.flac', '.m4a', '.webm', '.aac', '.opus')
|
||||
if not any(attachment.filename.lower().endswith(ext) for ext in audio_extensions):
|
||||
await ctx.send(
|
||||
f"❌ Invalid file type: `{attachment.filename}`\n"
|
||||
f"**Supported formats:** MP3, MP4, WAV, OGG, FLAC, M4A, WEBM, AAC, OPUS"
|
||||
f"**Supported formats:** MP3, MP4, WAV, OGG, FLAC, M4A, WEBM, AAC, OPUS",
|
||||
ephemeral=True if ctx.interaction else False
|
||||
)
|
||||
return
|
||||
|
||||
# Defer for slash commands since processing takes time
|
||||
if ctx.interaction:
|
||||
await ctx.defer()
|
||||
|
||||
await util.join_vc(ctx)
|
||||
await ctx.message.add_reaction('📎')
|
||||
|
||||
# Add reaction for prefix commands only
|
||||
if not ctx.interaction:
|
||||
await ctx.message.add_reaction('📎')
|
||||
|
||||
msg = await ctx.send(f"Processing file: `{attachment.filename}`...")
|
||||
|
||||
@@ -184,7 +201,8 @@ class music(commands.Cog):
|
||||
await msg.delete()
|
||||
|
||||
if len(audio) == 0:
|
||||
await ctx.message.add_reaction('🚫')
|
||||
if not ctx.interaction:
|
||||
await ctx.message.add_reaction('🚫')
|
||||
await ctx.send("❌ Failed to process the audio file!")
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user