Scalars doesn't return None if the thing doesn't exists while scalar does.
This commit is contained in:
@@ -49,10 +49,15 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name)
|
stmt = select(Votes).where(Votes.ElectionCycle == election_name)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
try:
|
# Check if election exists.
|
||||||
|
if session.scalar(stmt) is None:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"Invalid election: {election_name}.", ephemeral=True
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
votes = session.scalars(stmt)
|
votes = session.scalars(stmt)
|
||||||
content = ""
|
content = ""
|
||||||
|
|
||||||
for vote in votes:
|
for vote in votes:
|
||||||
content += (
|
content += (
|
||||||
f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n"
|
f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n"
|
||||||
@@ -61,10 +66,6 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
)
|
)
|
||||||
|
|
||||||
await interaction.response.send_message(content=content, ephemeral=True)
|
await interaction.response.send_message(content=content, ephemeral=True)
|
||||||
except:
|
|
||||||
await interaction.response.send_message(
|
|
||||||
f"Invalid election: {election_name}.", ephemeral=True
|
|
||||||
)
|
|
||||||
|
|
||||||
@votes.on_autocomplete("election_name")
|
@votes.on_autocomplete("election_name")
|
||||||
async def election_autocomplete(
|
async def election_autocomplete(
|
||||||
|
|||||||
Reference in New Issue
Block a user