From 687b182e06997d5c48683ec98909d9df89deda26 Mon Sep 17 00:00:00 2001 From: ChaoticNebula <69293452+ChaoticNebula5@users.noreply.github.com> Date: Sat, 25 Sep 2021 12:24:03 +0530 Subject: [PATCH 1/2] Added a Rock paper scissors command using discord-components which means buttons! Let me know if y'all want it without the buttons! --- cogs/Minigames.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++ main.py | 2 ++ requirements.txt | 1 + 3 files changed, 58 insertions(+) diff --git a/cogs/Minigames.py b/cogs/Minigames.py index 6881803..1406a36 100644 --- a/cogs/Minigames.py +++ b/cogs/Minigames.py @@ -41,6 +41,61 @@ async def _2048(self, ctx): await message.add_reaction('⬅') await message.add_reaction('❌') + @commands.command(aliases=['rps']) + async def rockpaperscissors(self, ctx): + ch1 = ["Rock","Scissors","Paper"] + comp = choice(ch1) + + yet = discord.Embed(title = f"{ctx.author.display_name}'s Rock Paper Scissors Game!", description = f"Status: You haven't clicked on any button yet!", color = ctx.author.color) + + win = discord.Embed(title = f"{ctx.author.display_name}, You Won!", description = f"Status: **You have won!** Bot chose {comp}", color = 0x00FF00) + + out = discord.Embed(title = f"{ctx.author.display_name}, You did not click on time!", description = f"Status: **Timed Out!**", color = discord.Colour.red()) + + lost = discord.Embed(title = f"{ctx.author.display_name}, You Lost!!", description = f"Status: **You have Lost!** Bot had chosen {comp}", color = discord.Color.red()) + + tie = discord.Embed(title = f"{ctx.author.display_name}, It was a Tie!", description = f"Status: **Tie!**, Bot had chosen {comp}", color = ctx.author.color) + m = await ctx.send( + embed=yet, + components=[[Button(style=1, label="Rock"),Button(style=3, label="Paper"),Button(style=ButtonStyle.red, label="Scissors")] + ], + ) + def check(res): + return ctx.author == res.user and res.channel == ctx.channel + + try: + res = await client.wait_for("button_click", check=check, timeout=15) + player = res.component.label + + if player==comp: + await m.edit(embed=tie,components=[]) + + if player=="Rock" and comp=="Paper": + await m.edit(embed=lost,components=[]) + + if player=="Rock" and comp=="Scissors": + await m.edit(embed=win,components=[]) + + + if player=="Paper" and comp=="Rock": + await m.edit(embed=win,components=[]) + + if player=="Paper" and comp=="Scissors": + await m.edit(embed=lost,components=[]) + + + if player=="Scissors" and comp=="Rock": + await m.edit(embed=lost,components=[]) + + if player=="Scissors" and comp=="Paper": + await m.edit(embed=win,components=[]) + + + except TimeoutError: + await m.edit( + embed=out, + components=[], + ) def setup(bot): bot.add_cog(Minigames(bot)) diff --git a/main.py b/main.py index 69eb7ff..56c5fb5 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import discord from discord.ext import commands, tasks from dotenv import load_dotenv +from discord_components import * from main_resources.events import Events from main_resources.functions import * @@ -45,6 +46,7 @@ def get_prefix(bot, message: discord.Message): async def on_ready(): change_status.start() clear_game.start() + DiscordComponents(client) print("Updating databases...") update_guilds_data(bot, guilds_data, DEFAULT_PREFIX) print(f'Logged in as {bot.user.name}#{bot.user.discriminator} ID = {bot.user.id}') diff --git a/requirements.txt b/requirements.txt index ca0c887..eef2334 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ asyncio~=3.4.3 python-dotenv~=0.17.1 requests~=2.25.1 discord~=1.0.1 +discord-components==1.1.4 numpy~=1.19.5 keras~=2.4.3 nltk~=3.6.2 From 43f0d3c7513df4456523c85bd43b5c7bdafdae9f Mon Sep 17 00:00:00 2001 From: ChaoticNebula <69293452+ChaoticNebula5@users.noreply.github.com> Date: Sat, 25 Sep 2021 12:28:07 +0530 Subject: [PATCH 2/2] Update Minigames.py --- cogs/Minigames.py | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/cogs/Minigames.py b/cogs/Minigames.py index 1406a36..f2292ba 100644 --- a/cogs/Minigames.py +++ b/cogs/Minigames.py @@ -43,59 +43,59 @@ async def _2048(self, ctx): @commands.command(aliases=['rps']) async def rockpaperscissors(self, ctx): - ch1 = ["Rock","Scissors","Paper"] - comp = choice(ch1) + ch1 = ["Rock","Scissors","Paper"] + comp = choice(ch1) - yet = discord.Embed(title = f"{ctx.author.display_name}'s Rock Paper Scissors Game!", description = f"Status: You haven't clicked on any button yet!", color = ctx.author.color) + yet = discord.Embed(title = f"{ctx.author.display_name}'s Rock Paper Scissors Game!", description = f"Status: You haven't clicked on any button yet!", color = ctx.author.color) - win = discord.Embed(title = f"{ctx.author.display_name}, You Won!", description = f"Status: **You have won!** Bot chose {comp}", color = 0x00FF00) + win = discord.Embed(title = f"{ctx.author.display_name}, You Won!", description = f"Status: **You have won!** Bot chose {comp}", color = 0x00FF00) - out = discord.Embed(title = f"{ctx.author.display_name}, You did not click on time!", description = f"Status: **Timed Out!**", color = discord.Colour.red()) + out = discord.Embed(title = f"{ctx.author.display_name}, You did not click on time!", description = f"Status: **Timed Out!**", color = discord.Colour.red()) - lost = discord.Embed(title = f"{ctx.author.display_name}, You Lost!!", description = f"Status: **You have Lost!** Bot had chosen {comp}", color = discord.Color.red()) + lost = discord.Embed(title = f"{ctx.author.display_name}, You Lost!!", description = f"Status: **You have Lost!** Bot had chosen {comp}", color = discord.Color.red()) - tie = discord.Embed(title = f"{ctx.author.display_name}, It was a Tie!", description = f"Status: **Tie!**, Bot had chosen {comp}", color = ctx.author.color) - m = await ctx.send( + tie = discord.Embed(title = f"{ctx.author.display_name}, It was a Tie!", description = f"Status: **Tie!**, Bot had chosen {comp}", color = ctx.author.color) + m = await ctx.send( embed=yet, components=[[Button(style=1, label="Rock"),Button(style=3, label="Paper"),Button(style=ButtonStyle.red, label="Scissors")] ], ) - def check(res): - return ctx.author == res.user and res.channel == ctx.channel + def check(res): + return ctx.author == res.user and res.channel == ctx.channel - try: - res = await client.wait_for("button_click", check=check, timeout=15) - player = res.component.label + try: + res = await client.wait_for("button_click", check=check, timeout=15) + player = res.component.label - if player==comp: - await m.edit(embed=tie,components=[]) + if player==comp: + await m.edit(embed=tie,components=[]) - if player=="Rock" and comp=="Paper": - await m.edit(embed=lost,components=[]) + if player=="Rock" and comp=="Paper": + await m.edit(embed=lost,components=[]) - if player=="Rock" and comp=="Scissors": - await m.edit(embed=win,components=[]) + if player=="Rock" and comp=="Scissors": + await m.edit(embed=win,components=[]) - if player=="Paper" and comp=="Rock": - await m.edit(embed=win,components=[]) + if player=="Paper" and comp=="Rock": + await m.edit(embed=win,components=[]) - if player=="Paper" and comp=="Scissors": - await m.edit(embed=lost,components=[]) + if player=="Paper" and comp=="Scissors": + await m.edit(embed=lost,components=[]) - if player=="Scissors" and comp=="Rock": - await m.edit(embed=lost,components=[]) + if player=="Scissors" and comp=="Rock": + await m.edit(embed=lost,components=[]) - if player=="Scissors" and comp=="Paper": - await m.edit(embed=win,components=[]) + if player=="Scissors" and comp=="Paper": + await m.edit(embed=win,components=[]) - except TimeoutError: - await m.edit( - embed=out, - components=[], - ) + except TimeoutError: + await m.edit( + embed=out, + components=[], + ) def setup(bot): bot.add_cog(Minigames(bot))