mirror of
https://github.com/ssyyhhrr/discord.py-bot.git
synced 2025-11-10 14:13:45 -05:00
Quiz
This commit is contained in:
36
main.py
36
main.py
@@ -31,7 +31,7 @@ async def ping(ctx):
|
|||||||
@bot.command()
|
@bot.command()
|
||||||
async def coins(ctx):
|
async def coins(ctx):
|
||||||
getConfig()
|
getConfig()
|
||||||
await ctx.reply(f"You have {str(data[str(ctx.message.author.id)]['coins'])} coins.")
|
await ctx.reply(f"You have **{str(data[str(ctx.message.author.id)]['coins'])}** coins.")
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def roulette(ctx, bet = None, colour = None):
|
async def roulette(ctx, bet = None, colour = None):
|
||||||
@@ -52,7 +52,6 @@ async def roulette(ctx, bet = None, colour = None):
|
|||||||
if data[str(ctx.message.author.id)]["coins"] < betAmount:
|
if data[str(ctx.message.author.id)]["coins"] < betAmount:
|
||||||
await ctx.send("You do not have sufficient coins.")
|
await ctx.send("You do not have sufficient coins.")
|
||||||
return
|
return
|
||||||
|
|
||||||
select = random.randint(0, 1)
|
select = random.randint(0, 1)
|
||||||
if didWin(colour, select):
|
if didWin(colour, select):
|
||||||
data[str(ctx.message.author.id)]["coins"] += betAmount
|
data[str(ctx.message.author.id)]["coins"] += betAmount
|
||||||
@@ -61,6 +60,39 @@ async def roulette(ctx, bet = None, colour = None):
|
|||||||
setConfig()
|
setConfig()
|
||||||
await ctx.send(f"{'🔴' if select == 0 else '⚫'} The ball landed on {'red' if select == 0 else 'black'}. You {'won' if (didWin(colour, select)) else 'lost'} **{betAmount * (2 if (didWin(colour, select)) else 1)}** coins{'!' if (didWin(colour, select)) else '.'}")
|
await ctx.send(f"{'🔴' if select == 0 else '⚫'} The ball landed on {'red' if select == 0 else 'black'}. You {'won' if (didWin(colour, select)) else 'lost'} **{betAmount * (2 if (didWin(colour, select)) else 1)}** coins{'!' if (didWin(colour, select)) else '.'}")
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
async def quiz(ctx):
|
||||||
|
getConfig()
|
||||||
|
with open("questions.json", "r") as f:
|
||||||
|
questionsArr = json.load(f)
|
||||||
|
question = random.choice(questionsArr)
|
||||||
|
EMBED = discord.Embed(title="Quiz Question", description=question[0], color=0xffa500)
|
||||||
|
EMBED.add_field(name="Answers", value="**1.** True\n**2.** False")
|
||||||
|
message = await ctx.reply(embed=EMBED)
|
||||||
|
await message.add_reaction("1️⃣")
|
||||||
|
await message.add_reaction("2️⃣")
|
||||||
|
def check(reaction, user):
|
||||||
|
return user == ctx.message.author and (str(reaction.emoji) == "1️⃣" or str(reaction.emoji) == "2️⃣")
|
||||||
|
try:
|
||||||
|
reaction, user = await bot.wait_for("reaction_add", timeout=60.0, check=check)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
EMBED = discord.Embed(title="Quiz Question", description=question[0], color=0x808080)
|
||||||
|
EMBED.add_field(name="Answers", value="**1.** True\n**2.** False")
|
||||||
|
await message.edit(embed=EMBED)
|
||||||
|
else:
|
||||||
|
if (str(reaction.emoji) == "1️⃣" and question[1] == "true") or (str(reaction.emoji) == "2️⃣" and question[1] == "false"):
|
||||||
|
EMBED = discord.Embed(title="Quiz Question", description=question[0], color=0x00ff00)
|
||||||
|
EMBED.add_field(name="Answers", value="**1.** True\n**2.** False")
|
||||||
|
await message.edit(embed=EMBED)
|
||||||
|
data[str(ctx.message.author.id)]["coins"] += 100
|
||||||
|
setConfig()
|
||||||
|
await ctx.send(f"{ctx.message.author.mention}, you are correct! +**100** coins!")
|
||||||
|
else:
|
||||||
|
EMBED = discord.Embed(title="Quiz Question", description=question[0], color=0xff0000)
|
||||||
|
EMBED.add_field(name="Answers", value="**1.** True\n**2.** False")
|
||||||
|
await message.edit(embed=EMBED)
|
||||||
|
await ctx.send(f"{ctx.message.author.mention}, you are incorrect :(")
|
||||||
|
|
||||||
def getConfig():
|
def getConfig():
|
||||||
global data
|
global data
|
||||||
with open("users.json", "r") as f:
|
with open("users.json", "r") as f:
|
||||||
|
|||||||
2740
questions.json
Normal file
2740
questions.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"534077333443969026": {
|
"534077333443969026": {
|
||||||
"coins": 200
|
"coins": 5600
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user