Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Typehinting arguments and variable for examples #1855

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/views/channel_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ class DropdownView(discord.ui.View):
@discord.ui.channel_select(
placeholder="Select channels...", min_values=1, max_values=3
) # Users can select a maximum of 3 channels in the dropdown
async def channel_select_dropdown(self, select, interaction):
async def channel_select_dropdown(
self, select: discord.ui.Select, interaction: discord.Interaction
) -> None:
await interaction.response.send_message(
f"You selected the following channels:"
+ f", ".join(f"{channel.mention}" for channel in select.values)
)


bot = discord.Bot(debug_guilds=[...])
bot: discord.Bot = discord.Bot(debug_guilds=[...])


@bot.slash_command()
async def channel_select(ctx: discord.ApplicationContext):
async def channel_select(ctx: discord.ApplicationContext) -> None:
"""Sends a message with our dropdown that contains a channel select."""

# Create the view containing our dropdown
Expand All @@ -31,7 +33,7 @@ async def channel_select(ctx: discord.ApplicationContext):


@bot.event
async def on_ready():
async def on_ready() -> None:
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("------")

Expand Down
10 changes: 6 additions & 4 deletions examples/views/role_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ class DropdownView(discord.ui.View):
@discord.ui.role_select(
placeholder="Select roles...", min_values=1, max_values=3
) # Users can select a maximum of 3 roles in the dropdown
async def role_select_dropdown(self, select, interaction):
async def role_select_dropdown(
self, select: discord.ui.Select, interaction: discord.Interaction
) -> None:
await interaction.response.send_message(
f"You selected the following roles:"
+ f", ".join(f"{role.mention}" for role in select.values)
)


bot = discord.Bot(debug_guilds=[...])
bot: discord.Bot = discord.Bot(debug_guilds=[...])


@bot.slash_command()
async def role_select(ctx: discord.ApplicationContext):
async def role_select(ctx: discord.ApplicationContext) -> None:
"""Sends a message with our dropdown that contains a role select."""

# Create the view containing our dropdown
Expand All @@ -31,7 +33,7 @@ async def role_select(ctx: discord.ApplicationContext):


@bot.event
async def on_ready():
async def on_ready() -> None:
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("------")

Expand Down