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

added type hinting in code examples #451

Merged
merged 6 commits into from
Apr 20, 2024
Merged
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
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
Loading