Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
📝 added ctx to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunarmagpie committed Dec 12, 2021
1 parent 97b09ce commit f138503
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions docs/interactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,5 @@ The :class:`~pincer.objects.message.context.MessageContext` object provides meth
@command
async def some_other_command(self, ctx: MessageContext):
channel = await self.get_channel(ctx.channel_id)
channel.send("Hello world!") # Sends a message in the channel
ctx.channel.send("Hello world!") # Sends a message in the channel
return "Hello world 2" # This is sent because the interaction was not "used up"
11 changes: 5 additions & 6 deletions examples/guessing_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ async def guess(self, ctx: MessageContext, biggest_number: int):
f" Pick a number between 0 and {biggest_number}."
)

channel = await self.get_channel(ctx.channel_id)
number = random.randint(0, biggest_number)

try:
Expand All @@ -24,24 +23,24 @@ async def guess(self, ctx: MessageContext, biggest_number: int):
continue

if not next_message.content.isdigit():
await channel.send(
await ctx.channel.send(
f"{next_message.content} is not a number. Try again!"
)
continue

guessed_number = int(next_message.content)

if guessed_number > number:
await channel.send("Number is too high!")
await ctx.channel.send("Number is too high!")
elif guessed_number < number:
await channel.send("Number is too low!")
await ctx.channel.send("Number is too low!")
else:
await next_message.react("🚀")
await channel.send("Number is correct!")
await ctx.channel.send("Number is correct!")
break

except TimeoutError:
await channel.send("You took too long! The game timed out.")
await ctx.channel.send("You took too long! The game timed out.")


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion pincer/objects/message/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from ...utils.api_object import ChannelProperty, GuildProperty

if TYPE_CHECKING:

from typing import Optional, Union
Expand All @@ -18,7 +20,7 @@


@dataclass(repr=False)
class MessageContext:
class MessageContext(GuildProperty, ChannelProperty):
"""Represents the context of a message interaction.
Attributes
Expand Down

0 comments on commit f138503

Please sign in to comment.