D
D
DrunkCats2020-08-01 12:54:14
JavaScript
DrunkCats, 2020-08-01 12:54:14

How to make clear command on discord.js?

I want to follow the clear command for my bot.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dream, 2021-05-20
@dreameddd

If you want to delete all messages, then:

@bot.command()
async def clear(ctx):
    await ctx.channel.purge(limit=None)

If with the number of recent messages:
@bot.command()
async def clear(ctx, number:int=None): # кол-во сообщений по умолчанию не указано
    if number != None: # если кол-во сообщений указано, то удаляем указанное количество
        await ctx.channel.purge(limit=number + 1) # указанное количество + наше сообщение с командой
    else: # если кол-во сообщений не указано, то удаляем всё
        await ctx.channel.purge(limit=None)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question