support any audio file

This commit is contained in:
Nexus 2023-12-03 22:52:41 +00:00
parent 248d300c47
commit 32f512a5fa
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -2451,8 +2451,10 @@ class OtherCog(commands.Cog):
if not message.attachments:
return await ctx.respond("No attachments found.")
_ft = "wav"
for attachment in message.attachments:
if attachment.content_type == "audio/ogg":
if attachment.content_type == "audio/":
_ft = attachment.filename.split(".")[-1]
break
else:
return await ctx.respond("No voice messages.")
@ -2469,7 +2471,7 @@ class OtherCog(commands.Cog):
with tempfile.NamedTemporaryFile("wb+", suffix="-" + attachment.filename) as f2:
await attachment.save(f2.name)
f2.seek(0)
seg: pydub.AudioSegment = await asyncio.to_thread(pydub.AudioSegment.from_ogg, file=f2)
seg: pydub.AudioSegment = await asyncio.to_thread(pydub.AudioSegment.from_file, file=f2, format=_ft)
seg = seg.set_channels(1)
await asyncio.to_thread(
seg.export, f.name, format="mp4"