[英]TypeError: on_ready() missing 1 required positional argument: 'self' discord.py
[英](discord.py) TypeError: to_components() missing 1 required positional argument: 'self'
我正在嘗試使用 label “開放通道”和我的嵌入下方的原色獲得一個按鈕,但在測試時出現以下錯誤。 只有嵌入時不會發生這種情況。
這是我的代碼:
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
)
我用這個發送它(在一個更大的 function 內定義嵌入):
await bot.get_channel(876620293249048666).send(embed=embed, view=NegotiationButton)
我收到此錯誤:
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'
您正在發送 class 參考,但它需要一個實例。 嘗試這個:
..., view=NegotiationButton()) # ()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.