Conditions | 7 |
Total Lines | 35 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import random |
||
9 | @command() # note that the parenthesis are optional |
||
10 | async def guess(self, ctx: MessageContext, biggest_number: int): |
||
11 | await ctx.reply( |
||
12 | f"Starting the guessing game!" |
||
13 | f" Pick a number between 0 and {biggest_number}." |
||
14 | ) |
||
15 | |||
16 | number = random.randint(0, biggest_number) |
||
17 | |||
18 | try: |
||
19 | async for next_message in self.loop_for( |
||
20 | "on_message", loop_timeout=60 |
||
21 | ): |
||
22 | if next_message.author.bot: |
||
23 | continue |
||
24 | |||
25 | if not next_message.content.isdigit(): |
||
26 | await ctx.channel.send( |
||
27 | f"{next_message.content} is not a number. Try again!" |
||
28 | ) |
||
29 | continue |
||
30 | |||
31 | guessed_number = int(next_message.content) |
||
32 | |||
33 | if guessed_number > number: |
||
34 | await ctx.channel.send("Number is too high!") |
||
35 | elif guessed_number < number: |
||
36 | await ctx.channel.send("Number is too low!") |
||
37 | else: |
||
38 | await next_message.react("🚀") |
||
39 | await ctx.channel.send("Number is correct!") |
||
40 | break |
||
41 | |||
42 | except TimeoutError: |
||
43 | await ctx.channel.send("You took too long! The game timed out.") |
||
44 | |||
49 |