Skip to content

Commit 39a721d

Browse files
Yellow-BeansLulalabyDorukyum
authored
added type hinting in code examples (#451)
Signed-off-by: Lala Sabathil <[email protected]> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: Dorukyum <[email protected]>
1 parent 81c2b33 commit 39a721d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/getting-started/creating-your-first-bot.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ bot = discord.Bot()
134134
async def on_ready():
135135
print(f"{bot.user} is ready and online!")
136136

137-
@bot.slash_command(name = "hello", description = "Say hello to the bot")
138-
async def hello(ctx):
137+
@bot.slash_command(name="hello", description="Say hello to the bot")
138+
async def hello(ctx: discord.ApplicationContext):
139139
await ctx.respond("Hey!")
140140

141141
bot.run(os.getenv('TOKEN')) # run the bot with the token
@@ -190,8 +190,8 @@ the [`on_ready`](https://docs.pycord.dev/en/stable/api/events.html#discord.on_re
190190
event that is automatically called when the bot is ready to use.
191191

192192
```py
193-
@bot.slash_command(name = "hello", description = "Say hello to the bot")
194-
async def say_hello(ctx):
193+
@bot.slash_command(name="hello", description="Say hello to the bot")
194+
async def hello(ctx: discord.ApplicationContext):
195195
await ctx.respond("Hey!")
196196
```
197197

@@ -200,6 +200,8 @@ decorator to define a slash command. We specify the `name` and `description` arg
200200
specified, the name of the slash command would be the function name and the command description would
201201
be empty.
202202

203+
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).
204+
203205
Finally, you want to run the bot using the token specified in the `.env` file.
204206

205207
Now you have finished creating your first Pycord bot! What we have shown you is just the basic structure
@@ -223,8 +225,8 @@ bot = discord.Bot()
223225
async def on_ready():
224226
print(f"{bot.user} is ready and online!")
225227

226-
@bot.slash_command(name = "hello", description = "Say hello to the bot")
227-
async def hello(ctx):
228+
@bot.slash_command(name="hello", description="Say hello to the bot")
229+
async def hello(ctx: discord.ApplicationContext):
228230
await ctx.send("Hey!")
229231

230232
bot.run("TOKEN")

0 commit comments

Comments
 (0)