import discord
from discord.ext.commands import Bot
from discord.ext import commands
client = commands.Bot(command_prefix= '.')
#purging all members messages
#p stands for purge
@client.command()
async def p(ctx, number, age):
if str(age)=='old':
deleted = await ctx.channel.purge(limit=int(number), oldest_first=True)
await ctx.channel.send('Deleted {} message(s)'.format(len(deleted)))
print('Deleted {} message(s)'.format(len(deleted)))
elif str(age)=='new':
deleted = await ctx.channel.purge(limit=int(number), oldest_first=False)
await ctx.channel.send('Deleted {} message(s)'.format(len(deleted)))
print('Deleted {} message(s)'.format(len(deleted)))
else:
await ctx.channel.send('Must choose old or new messages')
#purging a specific member's messages starting from newest
#mp stands for member purge
#there is a 100 message bulk delete limit imposed by discord so this stops at 99
#once it finishes, you can simply rerun the command and do it again
#channel.delete_messges only works for messages up to 14 days old
@client.command()
async def mp(self, member: discord.Member=None):
await self.message.delete()
msg = []
async for m in self.channel.history(limit=None):
if len(msg)==99:
break
else:
if m.author == member:
msg.append(m)
await self.channel.delete_messages(msg)
print('Deleted {} message(s)'.format(len(msg)))
#mpo stands for member purge old
#this loops through all messages one by one and deletes them
#this can be used when needing to delete messages older than 14 days old
#takes a lot longer
@client.command()
async def mpo(self, member: discord.Member=None):
#this simply deletes your command
await self.message.delete()
counter=0
async for m in self.channel.history(limit=None):
if m.author == member:
counter+=1
await m.delete()
print(counter)
#make the bot talk with .send "the message"
@client.command()
async def send(self, msg):
await self.message.delete()
await self.channel.send(msg)
client.run('paste bot token here')