【发布时间】:2022-06-11 00:03:03
【问题描述】:
我想在另一个类中获取一个 cog 类的字符串,但我得到了错误
endpoint = cr().endpoint
TypeError: __init__() missing 1 required positional argument: 'client'
我尝试添加
def __init__(self, client):
self.client = client
进入 Button 的类,但我得到相同的 TypeError,我不知道我现在能做什么。
这是我需要帮助的代码部分:
class chest(discord.ui.View):
def __init__(self):
super().__init__()
@discord.ui.button(label='Nächste Truhen', style=discord.ButtonStyle.blurple, emoji="????")
async def next(self, interaction: discord.Interaction, button: discord.ui.Button):
endpoint = cr().endpoint
r2=requests.get(f"https://proxy.royaleapi.dev/v1/players/{endpoint}/upcomingchests", headers={"Accept":"application/json", "authorization":"Bearer here's an API Key
class cr(commands.Cog):
def __init__(self, client):
self.client = client
self.endpoint = ""
@app_commands.command(
name="crplayer",
description="heres a description"
)
async def crplayer(self,interaction: discord.Interaction,playertag:str):
base_url = "https://api.clashroyale.com/v1"
endpoint = f"%23{playertag.replace('#', '')}"
self.endpoint = endpoint
【问题讨论】:
-
requests.get行在最后被截断,打乱了其余代码的语法高亮显示。 -
调用
cr()需要client参数。
标签: python discord.py typeerror