Add random message from channel command

This commit is contained in:
2020-12-19 02:28:08 +01:00
parent d1ceedbf12
commit b0ccf2831b

18
bot.py
View File

@@ -114,7 +114,23 @@ async def on_message(message: discord.Message):
await bot.process_commands(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 = ''): async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = '', *, val: str = ''):
if ctx.guild is None: if ctx.guild is None:
await ctx.send('You can\'t run config commands in private messages!') await ctx.send('You can\'t run config commands in private messages!')