Discord.py "AttributeError: 'str' object has no attribute 'channel'"



我没有在我的代码中触摸任何东西,它之前是工作的,现在它不是我该怎么办?

我代码:

@commands.command(aliases=['Purge', "Clear", "clear"])
@commands.has_permissions(manage_messages = True)
async def purge(self,message,ctx,amount=2):
LOG_CHANNEL = self.client.get_channel(898771125482455041)
await ctx.channel.purge(limit=amount)
await ctx.message.delete()
await ctx.send(f":white_check_mark: Cleared `{amount}` Messages!")

embed=nextcord.Embed(title="Messages Cleared", color=0xf2ec00)
embed.add_field(name="Responsible Mod:", value=f"{ctx.author.name}", inline=False)
embed.add_field(name="Channel:", value=f"{ctx.channel.mention}", inline=False)
embed.add_field(name="Amount:", value=f"{amount}", inline=False)
await LOG_CHANNEL.send(embed=embed)

错误:AttributeError: 'str' object has no attribute 'channel'

你的参数被切换,ctx需要是第一个参数,除非在一个类中,它需要是第二个,在self之后。如果你交换messagectx,它应该工作。

async def purge(self, ctx, message, amount=2):

然而,我不确定为什么你首先有一个message参数,因为你似乎没有在任何地方使用它。如果你不使用它,你可以直接删除它,以避免丢失参数错误。

async def purge(self, ctx, amount=2):

相关内容