From ad01ca211a3d7bc9c24c47c3e70a446f0df11851 Mon Sep 17 00:00:00 2001 From: Jack Tealey <67752638+Kreusada@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:00:27 +0000 Subject: [PATCH] [Pick] v1.0.1 Fix for roles with no members --- pick/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pick/__init__.py b/pick/__init__.py index dbe0afac0..74613fb81 100644 --- a/pick/__init__.py +++ b/pick/__init__.py @@ -12,7 +12,7 @@ class Pick(commands.Cog): """Pick a random member.""" - __version__ = "1.0.0" + __version__ = "1.0.1" __author__ = "Kreusada, saurichable, AAA3A" async def red_delete_data_for_user(self, **kwargs): @@ -28,6 +28,8 @@ def format_help_for_context(self, ctx: commands.Context) -> str: async def pick(self, ctx: commands.Context, *, role: Optional[discord.Role] = None): """Pick a random member. You may supply a role to pick from.""" role = role or ctx.guild.default_role + if not role.members: + return await ctx.send("That role has no members to pick from.") winner = random.choice(role.members) embed = discord.Embed( description=f"- Mention: {winner.mention} ({inline(winner.mention)})\n- ID: {winner.id}", @@ -49,6 +51,8 @@ async def pickid(self, ctx: commands.Context, *, role: Optional[discord.Role] = This can be integrated with [nestedcommands by tmerc](https://github.com/tmercswims/tmerc-cogs) Example of usage: `[p]say Congratulations <@$(pick True)>! You won!` """ + if not role.members: + return await ctx.send("That role has no members to pick from.") await ctx.send(str(random.choice((role or ctx.guild.default_role).members).id))