Anudhyan Nath
Anudhyan Nath

Reputation: 21

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

I am making a discord and i am working on its clear message command but it shows this

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

Here's the full code

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))

Upvotes: 0

Views: 551

Answers (1)

Axisnix
Axisnix

Reputation: 2907

Don't add the .message attribute to it as it doesn't exist within TextChannel. ctx.channel.purge() will work

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))

Upvotes: 1

Related Questions