Repository: Rapptz/discord.py
File: examples/app_commands/basic.py (Python)

Code before:
bot = MyBot(command_prefix='?', intents=intents, application_id=...)


@bot.event
async def on_ready():
    print(f'Logged in as {bot.user} (ID: {bot.user.id})')
    print('------')

@bot.tree.command()
async def hello(interaction: discord.Interaction):
    """Says hello!"""
    await interaction.response.send_message(f'Hi, {interaction.user.mention}')

@bot.tree.command()
@app_commands.describe(first_value='The first value you want to add something to', second_value='The value you want to add to the first value')
async def add(interaction: discord.Interaction, first_value: int, second_value: int):
    """Adds two numbers together."""
    await interaction.response.send_message(f'{first_value} + {second_value} = {first_value + second_value}')

# To make an argument optional, you can make it a default argument
@bot.tree.command()
@app_commands.describe(member='The member you want to get the joined date from, defaults to the user who uses the command')
async def joined(interaction: discord.Interaction, member: discord.Member = None):
    """Says when a member joined."""
    # By doing this we use the member that was provided, 
    # tho if this is None we use the user that has invoked the command
    member = member or interaction.user

    await interaction.response.send_message(f'{member} joined in {member.joined_at}')

bot.run('token')

Review comment (suggestion):
```suggestion
    # If no member is explicitly provided then we use the command user here
```

Code after:


intents = discord.Intents.default()

# In order to use a basic synchronization of the app commands in the setup_hook,
# you have replace the 0 with your bots application_id you find in the developer portal.
client = MyClient(intents=intents, application_id=0)


@client.event
async def on_ready():
    print(f'Logged in as {client.user} (ID: {client.user.id})')
    print('------')


@client.tree.command()
async def hello(interaction: discord.Interaction):
    """Says hello!"""
    await interaction.response.send_message(f'Hi, {interaction.user.mention}')


@client.tree.command()
@app_commands.describe(
    first_value='The first value you want to add something to',
    second_value='The value you want to add to the first value',
)
async def add(interaction: discord.Interaction, first_value: int, second_value: int):
    """Adds two numbers together."""
    await interaction.response.send_message(f'{first_value} + {second_value} = {first_value + second_value}')


# To make an argument optional, you can either give it a supported default argument
# or you can mark it as Optional from the typing library. This example does both.
@client.tree.command()
@app_commands.describe(member='The member you want to get the joined date from, defaults to the user who uses the command')
async def joined(interaction: discord.Interaction, member: Optional[discord.Member] = None):
    """Says when a member joined."""
    # If no member is explicitly provided then we use the command user here
    member = member or interaction.user

    await interaction.response.send_message(f'{member} joined in {member.joined_at}')


client.run('token')