Reputation: 17
I made a rock paper scissors game and it kind of works. But when I do for say .rps test it still works even know its supposed to only let you do .rps rock or paper or scissors. I've included all my imports if you would like to test it out.
import discord
from discord.ext import commands, tasks
import os
import random
import asyncio
from asyncio import gather
client = commands.Bot(command_prefix=".")
@client.command()
async def rps(ctx, user_choice):
rpsGame = ['rock', 'paper', 'scissors']
if user_choice == 'rock' or 'paper' or 'scissors':
await ctx.send(f'Choice: `{user_choice}`\nBot Choice: `{random.choice(rpsGame)}`')
elif user_choice != 'rock' or 'paper' or 'scissors':
await ctx.send('**Error** This command only works with rock, paper, or scissors.')
client.run('token')
Upvotes: 0
Views: 776
Reputation: 2370
or
is True
if either side of it is True
, and any non-empty string is "truthy." Here's what you meant to do:
if user_choice == 'rock' or user_choice == 'paper' or user_choice == 'scissors':
await ctx.send(f'Choice: `{user_choice}`\nBot Choice: `{random.choice(rpsGame)}`')
else:
await ctx.send('**Error** This command only works with rock, paper, or scissors.')
Upvotes: 0
Reputation: 4743
if user_choice == 'rock' or 'paper' or 'scissors':
, doesn't means that if user choice is one of them. It means if user choice is rock or paper exist or scissors exist. You need to change these statements:
@client.command()
async def rps(ctx, user_choice):
rpsGame = ['rock', 'paper', 'scissors']
if user_choice.lower() in rpsGame:
await ctx.send(f'Choice: `{user_choice}`\nBot Choice: `{random.choice(rpsGame)}`')
elif user_choice.lower() not in rpsGame:
await ctx.send('**Error** This command only works with rock, paper, or scissors.')
Upvotes: 1