Home

Published

- 1 min read

discord.py compress mp4 command

img of discord.py compress mp4 command

The solution for this is noted below

discord.py compress mp4 command

Solution

   import discord # pip install discord.py
from discord.ext import commands
import asyncio
import aiofiles # pip install aiofiles
import requests # pip install requests
from aspose_compressor import AsposeCompressor # pip install aspose-compressor

client= commands.Bot(command_prefix='!', self_bot=True)

loop = asyncio.get_event_loop()

# wrap aspose compressor in an asynchronous function
async def aspose_compress(file_path: str):
    ac = AsposeCompressor()
    file = await loop.run_in_executor(None, ac.compress_video, file_path)
    await loop.run_in_executor(None, file.save, "./compressed.mp4")

@client.command(name="compress-video")
async def compress_video(ctx):
    # downloading original video for later compression
    binaries = requests.get(ctx.message.attachments[0].url).content
    async with aiofiles.open("original.mp4", mode="wb") as f:
        await f.write(binaries)
        await f.close()
    # compressing the video
    await aspose_compress("./original.mp4")
    await ctx.send(file=discord.File("./compressed.mp4")

client.run('token')

Try other methods by searching on the site. That is if this doesn’t work