File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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' )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments