<filename>test_bot/cogs/misc.py
import io
from base64 import b64decode

import disnake
from disnake.ext import commands


class Misc(commands.Cog):
    def __init__(self, bot):
        self.bot: commands.Bot = bot

    def _get_file(self, description: str) -> disnake.File:
        # just a white 100x100 png
        data = b64decode(
            "<KEY>"
        )
        return disnake.File(io.BytesIO(data), "image.png", description=description)

    @commands.slash_command()
    async def attachment_desc(self, inter: disnake.AppCmdInter, desc: str = "test") -> None:
        """
        Send an attachment with the given description (or the default)

        Parameters
        ----------
        desc: The attachment description
        """
        await inter.response.send_message(file=self._get_file(desc))

    @commands.slash_command()
    async def attachment_desc_edit(self, inter: disnake.AppCmdInter, desc: str = "test") -> None:
        """
        Send a message with a button, which sends an attachment with the given description (or the default)

        Parameters
        ----------
        desc: The attachment description
        """
        button = disnake.ui.Button(label="edit")
        button.callback = lambda interaction: interaction.response.edit_message(
            file=self._get_file(desc)
        )

        view = disnake.ui.View()
        view.add_item(button)
        await inter.response.send_message(".", view=view)


def setup(bot):
    bot.add_cog(Misc(bot))
    print(f"> Extension {__name__} is ready\n")

<filename>test_bot/cogs/misc.py
import io
from base64 import b64decode

import disnake
from disnake.ext import commands


class Misc(commands.Cog):
    def __init__(self, bot):
        self.bot: commands.Bot = bot

    def _get_file(self, description: str) -> disnake.File:
        # just a white 100x100 png
        data = b64decode(
            "<KEY>"
        )
        return disnake.File(io.BytesIO(data), "image.png", description=description)

    @commands.slash_command()
    async def attachment_desc(self, inter: disnake.AppCmdInter, desc: str = "test") -> None:
        """
        Send an attachment with the given description (or the default)

        Parameters
        ----------
        desc: The attachment description
        """
        await inter.response.send_message(file=self._get_file(desc))

    @commands.slash_command()
    async def attachment_desc_edit(self, inter: disnake.AppCmdInter, desc: str = "test") -> None:
        """
        Send a message with a button, which sends an attachment with the given description (or the default)

        Parameters
        ----------
        desc: The attachment description
        """
        button = disnake.ui.Button(label="edit")
        button.callback = lambda interaction: interaction.response.edit_message(
            file=self._get_file(desc)
        )

        view = disnake.ui.View()
        view.add_item(button)
        await inter.response.send_message(".", view=view)


def setup(bot):
    bot.add_cog(Misc(bot))
    print(f"> Extension {__name__} is ready\n")

# just a white 100x100 png Send an attachment with the given description (or the default)          Parameters         ----------         desc: The attachment description Send a message with a button, which sends an attachment with the given description (or the default)          Parameters         ----------         desc: The attachment description