Reputation: 21
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
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