OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

(discord.py) TypeError: to_components() missing 1 required positional argument: 'self'

  • Thread starter Thread starter undonepotato
  • Start date Start date
U

undonepotato

Guest
I'm trying to get a button with the label "Open Channel" and the primary color underneath my embed, but I get the error below when testing. This doesn't happen when there's only the embed.

Here's my code:

Code:
class NegotiationButton(discord.ui.View):

    @discord.ui.button(label="Open Channel", style=discord.ButtonStyle.primary)
    async def negotiate(self, interaction: discord.Interaction, button: discord.ui.Button):
        button.disabled=True
        button.style=discord.ButtonStyle.danger
        button.label="Already Taken"

        ntcnameverify=True

        while ntcnameverify:
            newchannelname=f"trade-{random.randint(0,99999)}"
            for channel in mainguild.text_channels:
                if newchannelname==channel.name:
                    continue
                else:
                    ntcnameverify=False

        await mainguild.create_text_channel(
            name=newchannelname,
            overwrites={ #TODO Change these IDs
                mainguild.get_member(702419006010949693): discord.PermissionOverwrite(read_messages=True, send_messages=True)

            },
            category=bot.get_channel(1000099256998297681),
            postition=500
        )

I send it with this (inside a larger function to define the embed):

Code:
await bot.get_channel(876620293249048666).send(embed=embed, view=NegotiationButton)

I get this error:

Code:
Traceback (most recent call last):
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 200, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\User\OneDrive\Documents\Python Projects\Other Stuff\uc_systems_bot\bot.py", line 77, in offer
    await bot.get_channel(876620293249048666).send(embed=embed, view=NegotiationButton) #TODO Change channel ID and add logic for buy and sell channels
  File "C:\Users\User\anaconda3\lib\site-packages\discord\abc.py", line 1521, in send
    with handle_message_parameters(
  File "C:\Users\User\anaconda3\lib\site-packages\discord\http.py", line 188, in handle_message_parameters
    payload['components'] = view.to_components()

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

Traceback (most recent call last):
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\bot.py", line 1330, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 995, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 209, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: to_components() missing 1 required positional argument: 'self'
<p>I'm trying to get a button with the label "Open Channel" and the primary color underneath my embed, but I get the error below when testing. This doesn't happen when there's only the embed.</p>
<p>Here's my code:</p>
<pre class="lang-py prettyprint-override"><code>class NegotiationButton(discord.ui.View):

@discord.ui.button(label="Open Channel", style=discord.ButtonStyle.primary)
async def negotiate(self, interaction: discord.Interaction, button: discord.ui.Button):
button.disabled=True
button.style=discord.ButtonStyle.danger
button.label="Already Taken"

ntcnameverify=True

while ntcnameverify:
newchannelname=f"trade-{random.randint(0,99999)}"
for channel in mainguild.text_channels:
if newchannelname==channel.name:
continue
else:
ntcnameverify=False

await mainguild.create_text_channel(
name=newchannelname,
overwrites={ #TODO Change these IDs
mainguild.get_member(702419006010949693): discord.PermissionOverwrite(read_messages=True, send_messages=True)

},
category=bot.get_channel(1000099256998297681),
postition=500
)
</code></pre>
<p>I send it with this (inside a larger function to define the embed):</p>
<pre class="lang-py prettyprint-override"><code>await bot.get_channel(876620293249048666).send(embed=embed, view=NegotiationButton)
</code></pre>
<p>I get this error:</p>
<pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 200, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\User\OneDrive\Documents\Python Projects\Other Stuff\uc_systems_bot\bot.py", line 77, in offer
await bot.get_channel(876620293249048666).send(embed=embed, view=NegotiationButton) #TODO Change channel ID and add logic for buy and sell channels
File "C:\Users\User\anaconda3\lib\site-packages\discord\abc.py", line 1521, in send
with handle_message_parameters(
File "C:\Users\User\anaconda3\lib\site-packages\discord\http.py", line 188, in handle_message_parameters
payload['components'] = view.to_components()

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

Traceback (most recent call last):
File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\bot.py", line 1330, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 995, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 209, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: to_components() missing 1 required positional argument: 'self'
</code></pre>
 

Latest posts

Top