Answer the question
In order to leave comments, you need to log in
How to clear messages?
I'm trying to clear messages in a text channel with a command. I can't figure out why it doesn't work.
The code:
from discord.ext import commands
import asyncio
import discord
bot = commands.Bot(command_prefix='!')
@bot.command()
async def clear(ctx, numb,):
channel = ctx.channel
numb = int(numb)
counter = 0
async for i in channel.history(ctx.message.channel, limit=numb):
if counter < numb:
await channel.delete_messages(i)
counter += 1
Answer the question
In order to leave comments, you need to log in
What error does it give?
You can also use this command:
import discord
from discord.ext import commands
import asyncio
bot = commands.Bot(command_prefix='!')
@bot.command()
async def clear (ctx, numb):
channel = ctx.channel
numb = int(numb)
await channel.purge(limit=numb+1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question