Reputation: 1
I coded a /coinflip command in python for my discord bot economy system. Now I can't figure out how to set two choices for the slash command so it is either head or tails.
I tried to implement the choices via defining choices = ... when using it as a ctx command, it works just fine but when using a slash command it just prints out errors or wotn even start.
@bot.tree.command(name="coinflip", description="Wirf eine Münze und schau was passiert!")
async def coinflip(interaction: discord.Interaction):
userid = str(interaction.user.id)
choices = ["kopf", "zahl"]
botchoice = random.choice(choices)
filename = f"database/{userid}.txt"
if choices == botchoice:
if os.path.isfile(filename):
with open(filename, "r") as file:
coins = int(file.read())
newcoins = coins + 25
with open(filename, "w") as file:
file.write(str(newcoins))
await interaction.response.send_message(f"Du gewinnst 25 Münzen, da das Ergebnis {botchoice} war.", ephemeral=True)
else:
with open(filename, "w") as file:
file.write("25")
await interaction.response.send_message(f"Du gewinnst 25 Münzen, da das Ergebnis {botchoice} war.", ephemeral=True)
else:
await interaction.response.send_message(f"Das war wohl nix, da das Ergebnis leider {botchoice} war.", ephemeral=True)
Upvotes: -1
Views: 102
Reputation: 968
if choices == botchoice:
On this line you are comparing choices choices = ["kopf", "zahl"]
a list
with botchoice = random.choice(choices)
a string
Therefore, your function will always return false I guess what you wanted to do is something along the line of
if "kopf" == botchoice:
or
if "zahl" == botchoice
Upvotes: 0