Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a rock paper scissor commands using discord components which means buttons! #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions cogs/Minigames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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}')
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down