Fix error when no valid messages can be found for selection

This commit is contained in:
2020-12-19 13:27:18 +01:00
parent f7e68ba8d6
commit 812bacfa4e

3
bot.py
View File

@@ -123,6 +123,9 @@ async def random_message_command(ctx: commands.Context, channel: Optional[discor
channel = ctx.channel channel = ctx.channel
messages = async_filter(_is_message_allowed_for_operations, channel.history(limit=max_cnt)) messages = async_filter(_is_message_allowed_for_operations, channel.history(limit=max_cnt))
messages = [item async for item in messages] messages = [item async for item in messages]
if not messages:
await ctx.channel.send("No valid messages found!")
return
msg: discord.Message = random.choice(messages) msg: discord.Message = random.choice(messages)
author: discord.abc.User = msg.author author: discord.abc.User = msg.author
embed = discord.Embed( embed = discord.Embed(