mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
Fix minor convention mistakes in basic examples
Co-authored-by: Narmy <67862800+NarmyOnDiscord@users.noreply.github.com>
This commit is contained in:
parent
14e83dff0e
commit
61105ce925
@ -3,6 +3,7 @@ from typing import Optional
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
|
|
||||||
|
|
||||||
MY_GUILD = discord.Object(id=0) # replace with your guild id
|
MY_GUILD = discord.Object(id=0) # replace with your guild id
|
||||||
|
|
||||||
|
|
||||||
@ -13,14 +14,14 @@ class MyClient(discord.Client):
|
|||||||
# state required to make it work. This is a separate class because it
|
# state required to make it work. This is a separate class because it
|
||||||
# allows all the extra state to be opt-in.
|
# allows all the extra state to be opt-in.
|
||||||
# Whenever you want to work with application commands, your tree is used
|
# Whenever you want to work with application commands, your tree is used
|
||||||
# to store it and work with it.
|
# to store and work with them.
|
||||||
# Note: When using commands.Bot instead of discord.Client, the bot will
|
# Note: When using commands.Bot instead of discord.Client, the bot will
|
||||||
# maintain its own tree instead.
|
# maintain its own tree instead.
|
||||||
self.tree = app_commands.CommandTree(self)
|
self.tree = app_commands.CommandTree(self)
|
||||||
|
|
||||||
# In this basic example, we just synchronize the app commands to one guild.
|
# In this basic example, we just synchronize the app commands to one guild.
|
||||||
# Instead of specifying a guild to every command, we copy over our global commands instead.
|
# Instead of specifying a guild to every command, we copy over our global commands instead.
|
||||||
# By doing so we don't have to wait up to an hour until they are shown to the end-user.
|
# By doing so, we don't have to wait up to an hour until they are shown to the end-user.
|
||||||
async def setup_hook(self):
|
async def setup_hook(self):
|
||||||
# This copies the global commands over to your guild.
|
# This copies the global commands over to your guild.
|
||||||
self.tree.copy_global_to(guild=MY_GUILD)
|
self.tree.copy_global_to(guild=MY_GUILD)
|
||||||
@ -30,7 +31,7 @@ class MyClient(discord.Client):
|
|||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
|
|
||||||
# In order to use a basic synchronization of the app commands in the setup_hook,
|
# 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.
|
# you have to replace the 0 with your bot's application_id that you find in the developer portal.
|
||||||
client = MyClient(intents=intents, application_id=0)
|
client = MyClient(intents=intents, application_id=0)
|
||||||
|
|
||||||
|
|
||||||
@ -57,16 +58,16 @@ async def add(interaction: discord.Interaction, first_value: int, second_value:
|
|||||||
|
|
||||||
|
|
||||||
# To make an argument optional, you can either give it a supported default argument
|
# 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.
|
# or you can mark it as Optional from the typing standard library. This example does both.
|
||||||
@client.tree.command()
|
@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')
|
@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):
|
async def joined(interaction: discord.Interaction, member: Optional[discord.Member] = None):
|
||||||
"""Says when a member joined."""
|
"""Says when a member joined."""
|
||||||
# If no member is explicitly provided then we use the command user here
|
# If no member is explicitly provided then we use the command user here
|
||||||
member = member or interaction.user
|
member = member or interaction.user
|
||||||
|
|
||||||
# The format_dt function formats the date time into a human readable representation in the official client
|
# The format_dt function formats the date time into a human readable representation in the official client
|
||||||
await interaction.response.send_message(f'{member} joined in {discord.utils.format_dt(member.joined_at)}')
|
await interaction.response.send_message(f'{member} joined {discord.utils.format_dt(member.joined_at)}')
|
||||||
|
|
||||||
|
|
||||||
# A Context Menu command is an app command that can be run on a member or on a message by
|
# A Context Menu command is an app command that can be run on a member or on a message by
|
||||||
@ -77,7 +78,7 @@ async def joined(interaction: discord.Interaction, member: Optional[discord.Memb
|
|||||||
@client.tree.context_menu(name='Show Join Date')
|
@client.tree.context_menu(name='Show Join Date')
|
||||||
async def show_join_date(interaction: discord.Interaction, member: discord.Member):
|
async def show_join_date(interaction: discord.Interaction, member: discord.Member):
|
||||||
# The format_dt function formats the date time into a human readable representation in the official client
|
# The format_dt function formats the date time into a human readable representation in the official client
|
||||||
await interaction.response.send_message(f'{member} joined in {discord.utils.format_dt(member.joined_at)}')
|
await interaction.response.send_message(f'{member} joined at {discord.utils.format_dt(member.joined_at)}')
|
||||||
|
|
||||||
|
|
||||||
# This context menu command only works on messages
|
# This context menu command only works on messages
|
||||||
|
@ -57,7 +57,7 @@ async def repeat(ctx, times: int, content='repeating...'):
|
|||||||
@bot.command()
|
@bot.command()
|
||||||
async def joined(ctx, member: discord.Member):
|
async def joined(ctx, member: discord.Member):
|
||||||
"""Says when a member joined."""
|
"""Says when a member joined."""
|
||||||
await ctx.send(f'{member.name} joined in {member.joined_at}')
|
await ctx.send(f'{member.name} joined {discord.utils.format_dt(member.joined_at)}')
|
||||||
|
|
||||||
|
|
||||||
@bot.group()
|
@bot.group()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user