程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了命令引发异常:AttributeError: 'TextChannel' object has no attribute 'message'大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决命令引发异常:AttributeError: 'TextChAnnel' object has no attribute 'message'?

开发过程中遇到命令引发异常:AttributeError: 'TextChAnnel' object has no attribute 'message'的问题如何解决?下面主要结合日常开发的经验,给出你关于命令引发异常:AttributeError: 'TextChAnnel' object has no attribute 'message'的解决方法建议,希望对你解决命令引发异常:AttributeError: 'TextChAnnel' object has no attribute 'message'有所启发或帮助;

我正在制造不和谐,我正在处理其明确的消息命令,但它显示了这一点

Command raised an exception: AttributeError: 'TextChAnnel' object has no attribute 'message'

这是完整的代码

from discord.ext import commands
class Clear(commands.Cog):
    def __init__(self,bot):
        self.bot = bot
    @commands.command()
    @commands.has_permissions(manage_messages=TruE)
    async def clear(self,ctx,amount=2):
        await ctx.chAnnel.message.purge(limit=amount)
def setup(bot):
    bot.add_cog(Clear(bot))

解决方法

不要向其添加 .message 属性,因为它不存在于 TextChAnnel 中。 ctx.chAnnel.purge() 会起作用

@H_772_23@from discord.ext import commands class Clear(commands.Cog): def __init__(self,bot): self.bot = bot @commands.command() @commands.has_permissions(manage_messages=TruE) async def clear(self,ctx,amount=2): await ctx.chAnnel.purge(limit=amount) def setup(bot): bot.add_cog(Clear(bot))

大佬总结

以上是大佬教程为你收集整理的命令引发异常:AttributeError: 'TextChannel' object has no attribute 'message'全部内容,希望文章能够帮你解决命令引发异常:AttributeError: 'TextChannel' object has no attribute 'message'所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。