Skip to content

Commit c8d76a7

Browse files
Add another example in slash_basic
1 parent 5920951 commit c8d76a7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

examples/app_commands/slash_basic.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import discord
22

3-
bot = discord.Bot()
3+
bot = discord.Bot()
4+
5+
# If you use commands.Bot, @bot.slash_command should be used for
6+
# slash commands. You can use @bot.slash_command with discord.Bot aswell
47

58

69
@bot.command(guild_ids=[...]) # create a slash command for the supplied guilds
710
async def hello(ctx):
811
"""Say hello to the bot""" # the command description can be supplied as the docstring
9-
await ctx.respond(f"Hello {ctx.author}!")
12+
await ctx.send(f"Hello {ctx.author}!")
1013

11-
@bot.command(name='global') # creates a global slash command (might take an hour to register)
14+
@bot.command(name='hi') # Not passing in guild_ids creates a global slash command (might take an hour to register)
1215
async def global_command(ctx, num: int): # Takes one integer parameter
13-
await ctx.respond(f"This is a global command, {num}!")
16+
await ctx.send(f"This is a global command, {num}!")
17+
18+
@bot.command(guild_ids=[...])
19+
async def joined(ctx, member: discord.Member = None): # Passing a default value makes the argument optional
20+
user = member or ctx.author
21+
await ctx.send(f'{user.name} joined at {discord.utils.format_dt(user.joined_at)}')
1422

1523
bot.run("TOKEN")

0 commit comments

Comments
 (0)