Skip to content

Commit ccc9381

Browse files
authored
Merge pull request #189 from ShivanshDengla/main
Added Discord Quiz Game
2 parents 185626c + 7d73e6c commit ccc9381

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

D/Discord Quiz Bot/bot.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import discord
2+
from discord.ext import commands
3+
import random
4+
5+
# Create a bot instance
6+
bot = commands.Bot(command_prefix='!')
7+
8+
# Define quiz questions and answers
9+
quiz_questions = {
10+
"What is the capital of France?": "Paris",
11+
"What is the largest planet in our solar system?": "Jupiter",
12+
# Add more questions and answers
13+
}
14+
15+
@bot.event
16+
async def on_ready():
17+
print(f'Logged in as {bot.user.name}')
18+
19+
@bot.command()
20+
async def start_quiz(ctx):
21+
question, answer = random.choice(list(quiz_questions.items()))
22+
await ctx.send(question)
23+
24+
def check(message):
25+
return message.author == ctx.author
26+
27+
try:
28+
user_response = await bot.wait_for('message', check=check, timeout=20)
29+
except asyncio.TimeoutError:
30+
await ctx.send("Time's up! The correct answer was: " + answer)
31+
else:
32+
if user_response.content.lower() == answer.lower():
33+
await ctx.send(f"Correct, {ctx.author.mention}!")
34+
else:
35+
await ctx.send(f"Sorry, that's incorrect. The correct answer was: {answer}")
36+
37+
# Run the bot with your bot token
38+
bot.run('YOUR_BOT_TOKEN')

0 commit comments

Comments
 (0)