Skip to content

Commit

Permalink
[Pick] v1.0.1 Fix for roles with no members
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreusada authored Jan 9, 2025
1 parent 6f6ece1 commit ad01ca2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}",
Expand All @@ -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))


Expand Down

0 comments on commit ad01ca2

Please sign in to comment.