Created
August 2, 2017 12:57
-
-
Save zekroTJA/26eda8ccdf4ccaafbe1450cd8f19b1cb to your computer and use it in GitHub Desktop.
PYTHON DISCORD BOT: #04 - Clear Command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import asyncio | |
async def ex(args, message, client, invoke): | |
try: | |
ammount = int(args[0]) + 1 if len(args) > 0 else 2 | |
except: | |
await client.send_message(message.channel, embed=discord.Embed(color=discord.Color.red(), descrition="Please enter a valid value for message ammount!")) | |
return | |
cleared = 0 | |
failed = 0 | |
async for m in client.logs_from(message.channel, limit=ammount): | |
try: | |
await client.delete_message(m) | |
cleared += 1 | |
except: | |
failed += 1 | |
pass | |
failed_str = "\n\nFailed to clear %s message(s)." % failed if failed > 0 else "" | |
returnmsg = await client.send_message(message.channel, embed=discord.Embed(color=discord.Color.blue(), description="Cleared %s message(s).%s" % (cleared, failed_str))) | |
await asyncio.sleep(4) | |
await client.delete_message(returnmsg) | |
# SCHNELLERE ALTERNATIVE: | |
# messages = [] | |
# async for m in client.logs_from(message.channel, limit=ammount): | |
# messages.append(m) | |
# await client.delete_messages(messages) | |
# return_msg = await client.send_message(message.channel, "Deleted %s messages." % ammount) | |
# await asyncio.sleep(4) | |
# await client.delete_message(return_msg) |
Ou met on le token du client ?
c'est une commande 👍 (et d'habitude on commente en anglais)
excuse us <3
async code, very bad, should use rewrite
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ou met on le token du client ?