Python: Making a Discord bot (Part 4: Clear)

preview_player
Показать описание
In this video, we learned how to create a simple clear command to delete messages from a discord channel.

If you have any suggestions for future videos, leave it in the comments below.

#DiscordBot #Rewrite
Рекомендации по теме
Комментарии
Автор

Suggestions of videos:
- Cogs(I need it, they've changed)
- Music commands
- Embeds

appuchia
Автор

If you want it to delete 5 messages (not including the command message) you can just type "limit=amount + 1" instead of "limit=amount"

oscwavcommentaccount
Автор

I think the following code is more effective:

@client.command()
async def clear(ctx, amount=5):
await ctx.message.delete()
await

It'll delete 5 other messages including the command message.

vocelia
Автор

Awesome!
Btw, will you cover playing music?

omrimg
Автор

I am saying it from trying so many things, it really works, thank you

jabatunnisha
Автор

Guys it's changed since he's made the video. Code would be:

@client.command()
async def clear(ctx, limit:int):
await
await ctx.send(f'{limit} messages have been cleared.')

(I've added a part where it repeats how many messages you've deleted.) Works and has been tested. Your welcome 👍👍

iceydex-archived
Автор

another workaround for having leftover messages is: on the limit line set limit equal to amount plus one, so it deletes its self plus all the amount of messages before it that you want to delete

boyscoutguitarist
Автор

Suggestion: set limit to amount+1 instead of amount, so it will not take into account your command message while deleting.

charliecohen
Автор

4:00 you can set +1 after amount=5 and it will kinda igore the .clear, it is smoother

tqmatvey
Автор

ur videos are so straight forward and good

KrXza
Автор

So, if u have say, 10 messages and u type the clear command, with a value of 10, there will be 1 left over, what i found works is when u set the limit=amount, u should change it to limit=amount + 1 and then if u run the command it will delete the 10 messages + the clear command

echophantom
Автор

If you have some client events like on_message method and your are wondering why are all of you client command events suppresed, you have to add into the on_message method something like "await to make sure to even try evaluate your commands if they're.

Fortexik
Автор

Hi, do u have any idea what to do with this? 'str' object has no attribute 'add_command'

MonX
Автор

thank you! this was very helpful and made it that when it cleared messages bot said in chat that i deleted messages and after that deletes the message what said thay have been cleared

repe
Автор

@client.command()
async def clear(ctx, amount = 5):
await ctx.channel.purge(limit = amount + 1)

Seems to work (makes the right number of messages delete)

jonnylpenman
Автор

if anyone else is having problems getting the bot to clear msgs, make sure to give it permission to manage msgs cuz my dumbass forgot to

sparkleface
Автор

Um in the discord API there is no client.command. I just get object has no attribute 'command'

BendigoBS
Автор

Updated version is below

@client.command()
async def clear(ctx, amount=100):
channel = ctx.message.channel
deleted = await channel.purge(limit=amount)
await channel.send('Deleted {}

ahmetsarkaya
Автор

I have two bots, on one it just works fine on the other one it is not working why?

corvo
Автор

If you want perms!
@client.command(aliases = ['purge', 'nuke', 'delete'])

async def clear(ctx, amount=5):
await ctx.send('Deleting...')
await

freebie.
join shbcf.ru