Skip to content

Commit

Permalink
added type hinting in code examples (#451)
Browse files Browse the repository at this point in the history
Signed-off-by: Lala Sabathil <[email protected]>
Co-authored-by: Lala Sabathil <[email protected]>
Co-authored-by: Dorukyum <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2024
1 parent 81c2b33 commit 39a721d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/getting-started/creating-your-first-bot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ 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")
async def hello(ctx):
@bot.slash_command(name="hello", description="Say hello to the bot")
async def hello(ctx: discord.ApplicationContext):
await ctx.respond("Hey!")

bot.run(os.getenv('TOKEN')) # run the bot with the token
Expand Down Expand Up @@ -190,8 +190,8 @@ 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")
async def say_hello(ctx):
@bot.slash_command(name="hello", description="Say hello to the bot")
async def hello(ctx: discord.ApplicationContext):
await ctx.respond("Hey!")
```

Expand All @@ -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 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.

Now you have finished creating your first Pycord bot! What we have shown you is just the basic structure
Expand All @@ -223,8 +225,8 @@ 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")
async def hello(ctx):
@bot.slash_command(name="hello", description="Say hello to the bot")
async def hello(ctx: discord.ApplicationContext):
await ctx.send("Hey!")

bot.run("TOKEN")
Expand Down

0 comments on commit 39a721d

Please sign in to comment.