#problem to get channel arg. in class

1 messages · Page 1 of 1 (latest)

little skiff
#

hey

#
@client.slash_command(guild_ids = servers, name="post-leaks", description="Postet einen Leak")
@commands.has_any_role(1073964313309614154)
async def postleak(ctx, channel: Option(discord.TextChannel, description="In welchem Channel soll der Leak gepostet werden?", required=True)):
    if channel is None:
        channel = ctx.channel

    await ctx.send_modal(PostLeakModal(title="✨ Leak Posten"))

class PostLeakModal(discord.ui.Modal):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        self.add_item(discord.ui.InputText(label="Name", placeholder="ws_hud"))
        self.add_item(discord.ui.InputText(label="Preview", placeholder="Placeholder"))
        self.add_item(discord.ui.InputText(label="Download", placeholder="Placeholder"))
        
    async def callback(self, interaction: discord.Interaction):
        embed = discord.Embed(title="\✨ Neuer Leak", color=0xff0000)
        embed.add_field(name="Name:", value=self.children[0].value, inline=False)
        embed.add_field(name="Preview:", value=self.children[1].value, inline=False)
        embed.add_field(name="Download:", value=self.children[2].value, inline=False)
        embed.set_author(name="FlareLeaks #2,0k", icon_url="https://cdn.discordapp.com/attachments/1073964316010758206/1079478593303875614/Founder.gif")
        embed.set_footer(text="Offizieller Bot by !Colin † ™ 🎾#0001 | FlareLeaks #2,0k", icon_url="https://cdn.discordapp.com/attachments/1073964316010758206/1079478593303875614/Founder.gif")
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/1073964316010758206/1079478593303875614/Founder.gif")
        await interaction.response.send_message("> Leak wurde erfolgreich gepostet!", ephemeral=True)
        await channel.send(embed=embed)```
#

how can i get the channel in the class that I have in the slash command?

lone zinc
#

Answered in #998272089343668364

little skiff
#

so

#

i need help

#

how can i pass it

oak prairie
little skiff
#

how

oak prairie
#

Learn OOP in python

#

Do you know how to accept args in a function?

#

As I said, accept the channel in the init method, and store it on a self variable

Then access it in the callback

lone zinc
#

They refrain to learn lmao

oak prairie
little skiff
#

Idk how

#

I dont often work with modals

lone zinc
#

You're working with a class. The answer that was provided is working with classes. Doesn't matter if its a view, modal or whatever. It is still a class and the concept is the same

little skiff
#

I dont work often wird classes Zoo

#

Too

lone zinc
#

Pycord is classes everywhere.

#

You won't get any further without that knowledge