Consider:
import os
import discord
import random
from discord.ext import commands
client = discord.Client()
bot = commands.Bot(command_prefix='!')
my_secret = os.environ['cleint']
Player = ''
ComPoint = 0
PlayerPoint = 0
turn = 0
gameOver = True
legalMoves = ['rock', 'paper', 'scissors']
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
@bot.command
async def rcp(ctx):
global Player
global turn
global count
global PlayerPoint
global ComPoint
if turn == 3:
turn = 0
count = 0
PlayerPoint = 0
ComPoint = 0
Player = ''
with open('images/rock_paper_scissors__2x.png', 'rb') as rcp:
picture = discord.File(rcp)
await ctx.send(file = picture)
await picture.add_reaction(':rock:')
await picture.add_reaction(':roll_of_paper:')
await picture.add_reaction(':scissors:')
comRandom = random.choice(legalMoves)
for reaction in picture.reactions:
''' Rock '''
if reaction.emoji == ':rock:' and comRandom == ':scissors:':
turn += 1
PlayerPoint += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
elif reaction.emoji == ':rock:' and comRandom == ':paper:':
turn += 1
ComPoint += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
elif reaction.emoji == ':rock:' and comRandom == ':rock:':
turn += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
''' Paper '''
if reaction.emoji == ':paper:' and comRandom == ':scissors:':
turn += 1
ComPoint += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
elif reaction.emoji == ':paper:' and comRandom == ':paper:':
turn += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
elif reaction.emoji == ':paper:' and comRandom == ':rock:':
turn += 1
PlayerPoint += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
''' Scissors '''
if reaction.emoji == ':scissors:' and comRandom == ':scissors:':
turn += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
elif reaction.emoji == ':scissors:' and comRandom == ':paper:':
turn += 1
PlayerPoint += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
elif reaction.emoji == ':scissors:' and comRandom == ':rock:':
turn += 1
ComPoint += 1
ctx.send("PLAYER: ", PlayerPoint, "COMPUTER: ", ComPoint)
client.run(my_secret)
What's my problem? I think the problem is from where I send the image in Discord. As it shows when I open the image if I bring it out of the block. It gives me another error.
I would try out doing like image.reaction, but I think it would be wrong.
I won't think the problem is from the logic of the game, because it doesn't even start when I use the command !rcp
.