Reputation: 21
As the title states, I'm trying to delete messages using my !purge command. I have this down already:
@bot.command()
@commands.has_permissions(manage_messages=True)
async def purge(ctx):
await delete_messages(ctx, member)
await ctx.send("Deleted messages")
It's saying that delete_messages
is not defined. Please help me!
Upvotes: 1
Views: 6124
Reputation: 114
So we are in year 2019. I'll help you with your code.
delete_messages
is a method of a TextChannel object.
In your line await delete_messages(ctx, member)
, add ctx.message.channel.
just before delete_messages.
Your line would then go like this:
await ctx.message.channel.delete_messages(ctx, member)
Hope that clears things up.
If it did, don't hesitate to 'accept' the answer by clicking the check mark.
Upvotes: 2
Reputation: 1141
This will delete only up to 99 messages (+ the purge command) at a time and the messages must be under 14 days old.
@bot.command(pass_context=True, name='purge', aliases=['purgemessages'], no_pm=True)
async def purge(ctx, number):
number = int(number)
if number > 99 or number < 1:
await ctx.send("I can only delete messages within a range of 1 - 99", delete_after=10)
else:
author = ctx.message.author
authorID = author.id
mgs = []
number = int(number)
channel = ctx.message.channel
async for x in bot.logs_from((channel), limit = int(number+1)):
mgs.append(x)
await delete_messages(mgs)
await ctx.send('Success!', delete_after=4)
Upvotes: 0