diff --git a/bot.py b/bot.py index 3495f82..3e430c9 100644 --- a/bot.py +++ b/bot.py @@ -114,7 +114,23 @@ async def on_message(message: discord.Message): await bot.process_commands(message) -@bot.command(name='config') +@bot.command(name='random_message', brief='Select a random message from a channel') +async def random_message_command(ctx: commands.Context, channel: Optional[discord.TextChannel] = None, + max_cnt: int = 100): + if channel is None: + channel = ctx.channel + messages = await channel.history(limit=max_cnt).flatten() + msg: discord.Message = random.choice(messages) + author: discord.abc.User = msg.author + embed = discord.Embed( + description=msg.content + "\n\n[Go to message](" + msg.jump_url + ")" + ) + embed.set_author(name=author.display_name, icon_url=author.avatar_url) + embed.set_footer(text="random message from #" + channel.name + " out of " + str(len(messages)) + " messages") + await ctx.channel.send(embed=embed) + + +@bot.command(name='config', brief='Change the configuration of this bot') async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = '', *, val: str = ''): if ctx.guild is None: await ctx.send('You can\'t run config commands in private messages!')