else
/elif
used after raise
PYL-R1720 21 # these are phrases that when said by a whitename, automatically bans them.
22 # for example: known scam URLs
23 done = guild_service.add_raid_phrase(phrase)
24 if not done: 25 raise commands.BadArgument("That phrase is already in the list.")
26 else:
27 await ctx.send_success(description=f"Added `{phrase}` to the raid phrase list!", delete_after=5)
301 @app_commands.describe(amount="Number of messages to purge")
302 @transform_context
303 async def purge(self, ctx: GIRContext, amount: app_commands.Range[int, 1, 100]) -> None:
304 if amount <= 0:305 raise commands.BadArgument(
306 "Number of messages to purge must be greater than 0")
307 elif amount >= 100:
327 reason = escape_mentions(reason)
328
329 # sanity checks
330 if case is None:331 raise commands.BadArgument(
332 message=f"{member} has no case with ID {case_id}")
333 elif case._type != "WARN":
110 @transform_context
111 async def end(self, ctx: GIRContext, message_id: str):
112 giveaway = guild_service.get_giveaway(_id=int(message_id))
113 if giveaway is None:114 raise commands.BadArgument(
115 "A giveaway with that ID was not found.")
116 elif giveaway.is_ended:
77 async def reroll(self, ctx: GIRContext, message_id: str):
78 g = guild_service.get_giveaway(_id=int(message_id))
79
80 if g is None: 81 raise commands.BadArgument(
82 "Couldn't find an ended giveaway by the provided ID.")
83 elif not g.is_ended:
raise
causes control flow to be disrupted, as it will exit the block.
It is recommended to check other conditions using another if
statement, and get rid of else
statements as they are unnecessary.
def check_magic_generator(attribute):
magic = get_magic_number(attribute)
if magic < 0:
raise ValueError(f"{attribute} looks invalid")
elif magic > 100
raise ValueError(f"{attribute} is very magical")
else:
return magic
def check_magic_generator(attribute):
magic = get_magic_number(attribute)
if magic < 0:
raise ValueError(f"{attribute} looks invalid")
if magic > 100
raise ValueError(f"{attribute} is very magical")
return magic