Created
August 22, 2020 12:20
-
-
Save alissone/f241bbacfa629c3faebb36df7860b87a to your computer and use it in GitHub Desktop.
Get last N messages from Discord using discord.py
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 time | |
| import asyncio | |
| last_messages = 5 | |
| token = "YOUR TOKEN HERE" | |
| client = discord.Client() | |
| @client.event | |
| async def on_message(message): | |
| channels = ["general"] | |
| if str(message.channel) in channels: | |
| if message.content == "!history": | |
| messages = await message.channel.history(limit=last_messages).flatten() | |
| messages.reverse() | |
| await message.channel.send(f"Last {last_messages} messages:") | |
| await message.channel.send([message.content for message in messages]) | |
| client.run(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment