How do I send an error message as an ephemeral message in a slash command? #337
Answered
by
Superguy2876
Superguy2876
asked this question in
Q&A
-
I have the following command. @lightbulb.option("coins", "The number of coins to flip.", int, default=1)
@lightbulb.command("flip", "Flip some coins.")
@lightbulb.implements(commands.SlashCommand)
async def flip(ctx: lightbulb.context.Context) -> None:
coins = ctx.options.coins
if coins <= 0:
await ctx.respond("Invalid number of coins.")
return
flipList = []
heads = 0
tails = 0
for _ in range(coins):
flipList.append(random.choice(["Heads", "Tails"]))
if flipList[-1] == "Heads":
heads += 1
else:
tails += 1
response = f"Flipping {coins} coins.\n"
response += f"Flipped {heads} heads and {tails} tails.\n"
response += f"{', '.join(flipList)}"
if len(response) > 2000:
response = f"Coin flip body too long.\nFlipping {coins} coins.\n Total Heads: {heads}, Total Tails: {tails}."
await ctx.respond(response) How do I send the "invalid number of coins" message as an ephemeral message? |
Beta Was this translation helpful? Give feedback.
Answered by
Superguy2876
Aug 14, 2023
Replies: 1 comment
-
For those looking here, I found the answer. So that part would look like. if coins <= 0:
await ctx.respond("Invalid number of coins.", flags=hikari.MessageFlag.EPHEMERAL)
return |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Superguy2876
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those looking here, I found the answer.
Put
flags=hikari.MessageFlag.EPHEMERAL
in the respond method.So that part would look like.