Discord.py: 'Context' 对象没有属性 'id' 错误
Discord.py: 'Context' object has no attribute 'id' error
我有一个 discord 的启动命令,它在 2 周前工作,但现在不工作了。这是代码和错误
@client.command()
async def kick(self, member: discord.Member, *, reason=None):
await discord.Guild.kick(self=self, user=member, reason=reason)
discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'Context' 对象没有属性 'id'
我不明白为什么,我研究了API,我觉得我做的一切都很好。
有些地方不正确,
首先,所有命令都传递一个 Context 对象作为它们的第一个参数,您可以在后面传递您的 Member 对象。该对象几乎包含您在处理命令时需要的所有内容。
接下来,要获得我们的公会,我们可以从 Context 对象中检索它,只需 ctx.guild
,然后从那里访问 .kick()
方法。
此外,不需要传递 self
对象,这只是因为我们在 class 中,我建议阅读 python 面向对象编程如果您不熟悉它,它会对使用 discord.py.
有很大帮助
@client.command()
async def kick(self, ctx: commands.Context, member: discord.Member, *, reason=None):
await ctx.guild.kick(user=member, reason=reason)
我有一个 discord 的启动命令,它在 2 周前工作,但现在不工作了。这是代码和错误
@client.command()
async def kick(self, member: discord.Member, *, reason=None):
await discord.Guild.kick(self=self, user=member, reason=reason)
discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'Context' 对象没有属性 'id'
我不明白为什么,我研究了API,我觉得我做的一切都很好。
有些地方不正确,
首先,所有命令都传递一个 Context 对象作为它们的第一个参数,您可以在后面传递您的 Member 对象。该对象几乎包含您在处理命令时需要的所有内容。
接下来,要获得我们的公会,我们可以从 Context 对象中检索它,只需 ctx.guild
,然后从那里访问 .kick()
方法。
此外,不需要传递 self
对象,这只是因为我们在 class 中,我建议阅读 python 面向对象编程如果您不熟悉它,它会对使用 discord.py.
@client.command()
async def kick(self, ctx: commands.Context, member: discord.Member, *, reason=None):
await ctx.guild.kick(user=member, reason=reason)