Call a function in a cog using a discord button

22 Views Asked by At

I try to have a button to add ppl to the enlistment of a game. i have a function in another cog that updates the enlistment. so once someone press the button i want it to run that function it adds the person to a mySQL database and then the enlistment cog runs it and displays it on an message in the discord.

class reserve(commands.Cog):
    def __init__(self, client):
            self.client = client

    class MyView(discord.ui.View):

        @discord.ui.button(style=discord.ButtonStyle.success, label="Enlist me")
        async def on_button_one_click(self, interaction: discord.Interaction, button: discord.ui.Button):
                enlistment = self.client.get_cog("Embed") #This part is not working
                await enlistment.enlistment(self) #This part is not working

This is the error I get

  File "f:\SeaWolf\pythonbot\cogs\reserves.py", line 31, in on_button_one_click
    enlistment = self.client.get_cog("Embed")
                 ^^^^^^^^^^^
AttributeError: 'MyView' object has no attribute 'client'

I can load the function from other cogs doing the same thing but with a slash command instead of a button but i wanted to make it a bit easier with a button.

0

There are 0 best solutions below