reticivis-net / mediaforge

A Discord bot for editing and creating videos, images, GIFs, and more!
https://discord.com/oauth2/authorize?client_id=780570413767983122
GNU General Public License v3.0
84 stars 28 forks source link

`/togif` with nothing replied to just raises an error #167

Closed theowocat closed 1 month ago

theowocat commented 1 year ago

Describe the bug

/togif with nothing replied to just raises an error with a traceback to report as an issue.

Traceback

DATETIME:2023-04-18 11:30:05.021941
COMMAND:
TRACEBACK:
Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/mediaforge-HXFskkj--py3.11/lib/python3.11/site-packages/discord/app_commands/commands.py", line 841, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mediaforge/src/commands/conversion.py", line 141, in togif
    await process(ctx, processing.ffmpeg.mp4togif, [["VIDEO"]])
  File "/mediaforge/src/core/process.py", line 157, in process
    raise e
  File "/mediaforge/src/core/process.py", line 131, in process
    raise processing.common.ReturnedNothing(f"Expected image, {func} returned nothing.")
processing.common.ReturnedNothing: Expected image, <function mp4togif at 0x7f2ffc4feb60> returned nothing.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/mediaforge-HXFskkj--py3.11/lib/python3.11/site-packages/discord/ext/commands/hybrid.py", line 438, in _invoke_with_namespace
    value = await self._do_call(ctx, ctx.kwargs)  # type: ignore
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.cache/pypoetry/virtualenvs/mediaforge-HXFskkj--py3.11/lib/python3.11/site-packages/discord/app_commands/commands.py", line 860, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'togif' raised an exception: ReturnedNothing: Expected image, <function mp4togif at 0x7f2ffc4feb60> returned nothing.

Expected Behavior

/togif with no arguments sending a message like "❌No argument given".

Steps To Reproduce

  1. use the /togif command without anything being replied to
  2. wait

Anything Else

No response

LouisP0 commented 1 year ago

I guess (as you said) that this error happens because you didn't pass the mediaparam "video", so the main problem is the error catching.

a correction would be :

        if len(ctx.message.attachments) < 1:
            await ctx.reply("Please add a video.", ephemeral=True)
        elif not(ctx.message.attachments[0].url.endswith(".mp4")):
            await ctx.reply("Bad format, please send a mp4.", ephemeral=True)
            ...
        else:
            await process(ctx, processing.ffmpeg.mp4togif, [["VIDEO"]])

P.S : There is the same issue for almost every conversions.

EDIT: The issue is already solved. image

reticivis-net commented 1 year ago

The error in question here isn’t about the source media, it’s that somehow the gif conversion function just isn’t returning anything. By default, MediaForge scans the channel for media and errors prematurely if nothing is found https://github.com/HexCodeFFF/mediaforge/blob/8e2ee00270947f55355e9f9f23f08f2f02e475c8/src/core/process.py#L148-L153

MediaForge doesn’t actually support sending attachments via slash commands it requires you to send them in the channel first then run the command where it will scan for attachments

reticivis-net commented 1 month ago

merged into #208