From 968dc0b892d19a75823de9c9c7bdd5b04e91a50b Mon Sep 17 00:00:00 2001 From: Shivansh Dengla <66008449+ShivanshDengla@users.noreply.github.com> Date: Fri, 20 Oct 2023 06:49:55 +0530 Subject: [PATCH] Discord Rock Paper Scissor Bot --- D/Discord Rock Paper Scissor Bot/bot.py | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 D/Discord Rock Paper Scissor Bot/bot.py diff --git a/D/Discord Rock Paper Scissor Bot/bot.py b/D/Discord Rock Paper Scissor Bot/bot.py new file mode 100644 index 00000000..20c794a1 --- /dev/null +++ b/D/Discord Rock Paper Scissor Bot/bot.py @@ -0,0 +1,59 @@ +import discord +import random + +# Define your bot's token +TOKEN = 'YOUR_BOT_TOKEN' + +# Define the prefix for bot commands +PREFIX = '!' + +# Define the choices for the game +choices = ["rock", "paper", "scissors"] + +# Create a bot instance +intents = discord.Intents.default() +intents.typing = False +intents.presences = False +client = discord.Client(intents=intents) + +@client.event +async def on_ready(): + print(f'We have logged in as {client.user.name}') + +@client.event +async def on_message(message): + if message.author == client.user: + return + + if message.content.startswith(PREFIX): + # Extract the command without the prefix + command = message.content[len(PREFIX):].lower() + + if command == 'rps': + # Let the user choose Rock, Paper, or Scissors + await message.channel.send("Rock, Paper, or Scissors? Please type your choice.") + + def check(msg): + return msg.author == message.author and msg.content.lower() in choices + + try: + user_choice = await client.wait_for('message', check=check, timeout=30) + user_choice = user_choice.content.lower() + except TimeoutError: + await message.channel.send("You took too long to make a choice. Game over.") + return + + bot_choice = random.choice(choices) + + await message.channel.send(f"I chose {bot_choice}.") + + if user_choice == bot_choice: + await message.channel.send("It's a tie!") + elif (user_choice == "rock" and bot_choice == "scissors") or \ + (user_choice == "paper" and bot_choice == "rock") or \ + (user_choice == "scissors" and bot_choice == "paper"): + await message.channel.send("You win!") + else: + await message.channel.send("I win!") + +client.run(TOKEN)