Add command to list all messages used for random selection
This commit is contained in:
16
bot.py
16
bot.py
@@ -138,6 +138,22 @@ async def random_message_command(ctx: commands.Context, channel: Optional[discor
|
||||
await ctx.channel.send(embed=embed)
|
||||
|
||||
|
||||
@bot.command(name='collect_messages', brief='Lists all messages with the given filters')
|
||||
async def collect_messages_command(ctx: commands.Context, channel: Optional[discord.TextChannel] = None,
|
||||
max_cnt: Optional[int] = 100, reaction_filter: Optional[str] = None):
|
||||
typing = ctx.channel.trigger_typing()
|
||||
if channel is None:
|
||||
channel = ctx.channel
|
||||
messages = async_filter(lambda m: _is_message_valid_for_selection(m, reaction_filter), channel.history(limit=max_cnt))
|
||||
messages = [item async for item in messages]
|
||||
embed = discord.Embed(
|
||||
title="List of matching messages",
|
||||
description='\n'.join([m.content for m in messages])
|
||||
)
|
||||
await typing
|
||||
await ctx.channel.send(embed=embed)
|
||||
|
||||
|
||||
def _is_message_valid_for_selection(message: discord.Message, reaction_filter: Optional[str] = None) -> bool:
|
||||
if message.clean_content.strip() == '':
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user