From 70d22b0cf16f0a4a049b091d8ff94585f036e6ff Mon Sep 17 00:00:00 2001 From: Yellow-Beans <116719049+Yellow-Beans@users.noreply.github.com> Date: Sat, 20 Apr 2024 02:13:29 +0200 Subject: [PATCH 1/6] Type hinting has been added to the examples --- docs/getting-started/creating-your-first-bot.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/getting-started/creating-your-first-bot.mdx b/docs/getting-started/creating-your-first-bot.mdx index 34e63231..fb6fa58a 100644 --- a/docs/getting-started/creating-your-first-bot.mdx +++ b/docs/getting-started/creating-your-first-bot.mdx @@ -135,7 +135,7 @@ async def on_ready(): print(f"{bot.user} is ready and online!") @bot.slash_command(name = "hello", description = "Say hello to the bot") -async def hello(ctx): +async def hello(ctx: discord.ApplicationContext): await ctx.respond("Hey!") bot.run(os.getenv('TOKEN')) # run the bot with the token @@ -191,7 +191,7 @@ event that is automatically called when the bot is ready to use. ```py @bot.slash_command(name = "hello", description = "Say hello to the bot") -async def say_hello(ctx): +async def say_hello(ctx: discord.ApplicationContext): await ctx.respond("Hey!") ``` From 4bfc1436dcf0a54f142b4b1a3735324be2c4dd84 Mon Sep 17 00:00:00 2001 From: Yellow-Beans <116719049+Yellow-Beans@users.noreply.github.com> Date: Sat, 20 Apr 2024 02:17:29 +0200 Subject: [PATCH 2/6] added typehinting to example code --- docs/getting-started/creating-your-first-bot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/creating-your-first-bot.mdx b/docs/getting-started/creating-your-first-bot.mdx index fb6fa58a..87416c21 100644 --- a/docs/getting-started/creating-your-first-bot.mdx +++ b/docs/getting-started/creating-your-first-bot.mdx @@ -224,7 +224,7 @@ async def on_ready(): print(f"{bot.user} is ready and online!") @bot.slash_command(name = "hello", description = "Say hello to the bot") -async def hello(ctx): +async def hello(ctx: discord.ApplicationContext): await ctx.send("Hey!") bot.run("TOKEN") From 18fb05c84f58a55d74b37e6789196962984e5a7c Mon Sep 17 00:00:00 2001 From: Yellow-Beans <116719049+Yellow-Beans@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:19:01 +0200 Subject: [PATCH 3/6] added text about the changes --- docs/getting-started/creating-your-first-bot.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/getting-started/creating-your-first-bot.mdx b/docs/getting-started/creating-your-first-bot.mdx index 87416c21..3bf77273 100644 --- a/docs/getting-started/creating-your-first-bot.mdx +++ b/docs/getting-started/creating-your-first-bot.mdx @@ -200,6 +200,8 @@ decorator to define a slash command. We specify the `name` and `description` arg specified, the name of the slash command would be the function name and the command description would be empty. +Optional: We typehint [': discord.ApplicationContext'](https://docs.pycord.dev/en/stable/api/application_commands.html#discord.ApplicationContext) to get access to autocompletion and docstrings. + Finally, you want to run the bot using the token specified in the `.env` file. Now you have finished creating your first Pycord bot! What we have shown you is just the basic structure From a1b9f8f8603dc67dfc1706f529b5d98c08d14ac1 Mon Sep 17 00:00:00 2001 From: Yellow-Beans <116719049+Yellow-Beans@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:36:34 +0200 Subject: [PATCH 4/6] removed white spaces that are correct when not used for arguments (e.g. when assigning variables) --- docs/getting-started/creating-your-first-bot.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/getting-started/creating-your-first-bot.mdx b/docs/getting-started/creating-your-first-bot.mdx index 3bf77273..8c8dad95 100644 --- a/docs/getting-started/creating-your-first-bot.mdx +++ b/docs/getting-started/creating-your-first-bot.mdx @@ -134,7 +134,7 @@ bot = discord.Bot() async def on_ready(): print(f"{bot.user} is ready and online!") -@bot.slash_command(name = "hello", description = "Say hello to the bot") +@bot.slash_command(name="hello", description="Say hello to the bot") async def hello(ctx: discord.ApplicationContext): await ctx.respond("Hey!") @@ -190,7 +190,7 @@ the [`on_ready`](https://docs.pycord.dev/en/stable/api/events.html#discord.on_re event that is automatically called when the bot is ready to use. ```py -@bot.slash_command(name = "hello", description = "Say hello to the bot") +@bot.slash_command(name="hello", description="Say hello to the bot") async def say_hello(ctx: discord.ApplicationContext): await ctx.respond("Hey!") ``` @@ -225,7 +225,7 @@ bot = discord.Bot() async def on_ready(): print(f"{bot.user} is ready and online!") -@bot.slash_command(name = "hello", description = "Say hello to the bot") +@bot.slash_command(name="hello", description="Say hello to the bot") async def hello(ctx: discord.ApplicationContext): await ctx.send("Hey!") From 155aacadd8bdedcd5c1962e34244889e019c29c0 Mon Sep 17 00:00:00 2001 From: Yellow-Beans <116719049+Yellow-Beans@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:43:02 +0200 Subject: [PATCH 5/6] added the recommended changes, made the function names consistent. --- docs/getting-started/creating-your-first-bot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/creating-your-first-bot.mdx b/docs/getting-started/creating-your-first-bot.mdx index 8c8dad95..9806510d 100644 --- a/docs/getting-started/creating-your-first-bot.mdx +++ b/docs/getting-started/creating-your-first-bot.mdx @@ -191,7 +191,7 @@ event that is automatically called when the bot is ready to use. ```py @bot.slash_command(name="hello", description="Say hello to the bot") -async def say_hello(ctx: discord.ApplicationContext): +async def hello(ctx: discord.ApplicationContext): await ctx.respond("Hey!") ``` From 47b38c754292c5b796026be8dc7d95af3636440c Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Sat, 20 Apr 2024 22:55:46 +0200 Subject: [PATCH 6/6] Update docs/getting-started/creating-your-first-bot.mdx Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Lala Sabathil --- docs/getting-started/creating-your-first-bot.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/creating-your-first-bot.mdx b/docs/getting-started/creating-your-first-bot.mdx index 9806510d..69f09ee8 100644 --- a/docs/getting-started/creating-your-first-bot.mdx +++ b/docs/getting-started/creating-your-first-bot.mdx @@ -200,7 +200,7 @@ decorator to define a slash command. We specify the `name` and `description` arg specified, the name of the slash command would be the function name and the command description would be empty. -Optional: We typehint [': discord.ApplicationContext'](https://docs.pycord.dev/en/stable/api/application_commands.html#discord.ApplicationContext) to get access to autocompletion and docstrings. +Optional: We type-hint the context parameter (`ctx`) as [`discord.ApplicationContext`](https://docs.pycord.dev/en/stable/api/application_commands.html#discord.ApplicationContext). In modern IDEs, type-hinting allows access to autocompletion and docstrings. You can read more about type-hinting [here](https://docs.python.org/3/library/typing.html). Finally, you want to run the bot using the token specified in the `.env` file.