AttributeError: 'Command' object has no attribute 'client' in discord.py

AttributeError: 'Command' object has no attribute 'client' in discord.py

这是有错误的代码行:

number = await self.client.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=20.0)

此行位于 'Shop' class 内,如下所示:

class Shop(commands.Cog, name="Shop"):
    """asks for a number of how much to buy"""

   def __init__(self, bot: commands.Bot):
    self.bot = bot

   # That line of code is somewhere here

def setup(bot: commands.Bot):
    bot.add_cog(Shop(bot))  

完整的错误如下所示:

number = await self.client.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=20.0)
AttributeError: 'Shop' object has no attribute 'client'

我是第一次处理齿轮,所以遇到这么多错误是有道理的。但是这个错误特别让我困扰了很长时间,我不知道该怎么做

我试过了:

number = await client.wait_for("message", check=lambda m: # and so on..)

number = await Bot.wait_for("message", check=lambda m: # and so on..)

number = await self.client.wait_for("message", check=lambda m: # and so on..)

他们中没有一个对我有用...这是处理 discord.py 我正在开发一个带有命令“Shop”的机器人,它要求输入(数字)“wait_for”并将其存储在变量“number”中,以便我可以在命令的其余部分中使用它。希望得到一些帮助,谢谢 -

如果你正确设置了 cogs,客户端就是机器人本身,所以你应该使用 self.bot:

number = await self.bot.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=20.0)