#Modals & message commands at the same time

1 messages · Page 1 of 1 (latest)

indigo flax
#

Hey,
I saw in a server a bot using message commands, that actually opened up a modal.

I wanted to reproduce that, and i made some kind of mix between the modals and the message commands, but it's not working sad
Here is my code so far (wich is in a cog btw):

@discord.message_command(name="Downvote", description="Downvote a message")
    async def downvote(self, ctx: discord.ApplicationContext, message: discord.Message):
        modal = discord.ui.Modal(title="Downvote")
        modal.add_item(discord.ui.InputText(label="Reason", style=discord.InputTextStyle.long))
        
        async def callback(ctx: discord.ApplicationContext):
            debug("Downvote sent !")
            embed = discord.Embed(title="Thanks for your feedback !", description="Your downvote has been sent to the developers. Thanks for your help !", color=discord.Color.og_blurple())
            embed.add_field(name="Message", value=modal.children[0].value)
            await ctx.respond(embed=embed, ephemeral=True)
            await ctx.send(f"Downvote from {ctx.author.mention} on {message.jump_url} for reason: {modal.children[0].value}")      
        await modal.callback(callback)
        await ctx.send_modal(modal)

It responds to the message command with a message that is immediatly deleted and opens the modal. So far everything is right. But the callback dosen't seem being called, because nothing happens when I click on submit.
I looked for some examples that did both, but didn't find anything. Please don't send me the modal example, I am not doing it like that because it ntaht case it was not sending that quick immediately deleted message.
Thank you for your help in advance

safe parrot
#

.rtfm context.send_modal

safe parrot
indigo flax
#

Yay thanks, worked. Idk with the example one wasn't working, perhaps cause I was in a cog

#

My code for people that'll come check here later:

import discord

class MyModal(discord.ui.Modal):
    def __init__(self, message):
        super().__init__(title="Downvote")
        self.add_item(discord.ui.InputText(label="Reason", style=discord.InputTextStyle.long))
        self.message = message

    async def callback(self, interaction: discord.Interaction):
        debug("Downvote sent !")
        embed = discord.Embed(title="Thanks for your feedback !", description="Your downvote has been sent to the developers. Thanks for your help !", color=discord.Color.og_blurple())
        embed.add_field(name="Message", value=self.children[0].value)
        await interaction.response.send_message(embed=embed, ephemeral=True)
        await interaction.channel.send(f"Downvote from {interaction.user.mention} on {self.message.jump_url} for reason: {self.children[0].value}")
class Chat (discord.Cog) :
    def __init__(self, bot: discord.Bot):
        super().__init__()
        self.bot = bot

    @discord.message_command(name="Downvote", description="Downvote a message")
    async def downvote(self, ctx: discord.ApplicationContext, message: discord.Message):
        modal = MyModal(message)
        await ctx.send_modal(modal)```