Я видел ботов, таких как Dyno, которые могут иметь 2 аргумента в одной команде косой черты, я хотел бы сделать то же самое с командой косой черты DM, которая была бы примерно такой: /dm @user Привет!
Я попытался использовать этот код в discord.py:
@tree.command(guild=discord.Object(id=guild_id), name='userping', description='DM the user to come back to the ticket')
@app_commands.describe(user = "The user you want the DM to be sent to", reason = "The reason to ping this user")
@app_commands.default_permissions(manage_channels=True)
@app_commands.checks.cooldown(3, 20, key=lambda i: (i.guild_id, i.user.id))
@app_commands.checks.bot_has_permissions(manage_channels=True)
async def userping(interaction: discord.Interaction, reason: str, user = discord.Member):
if "ticket-for-" in interaction.channel.name:
l=1
else:
await interaction.response.send_message("This isn't a ticket!", ephemeral=True)
Он возвращает:
Traceback (most recent call last):
File "/Users/Leo/Documents/code/Discord/TicketBot/discord_bot_python/bot2.py", line 215, in <module>
async def userping(interaction: discord.Interaction, reason: str, user = discord.Member):
File "/Users/Leo/Library/Python/3.9/lib/python/site-packages/discord/app_commands/tree.py", line 887, in decorator
command = Command(
File "/Users/Leo/Library/Python/3.9/lib/python/site-packages/discord/app_commands/commands.py", line 665, in __init__
self._params: Dict[str, CommandParameter] = _extract_parameters_from_callback(callback, callback.__globals__)
File "/Users/Leo/Library/Python/3.9/lib/python/site-packages/discord/app_commands/commands.py", line 370, in _extract_parameters_from_callback
raise TypeError(f'parameter {parameter.name!r} is missing a type annotation in callback {func.__qualname__!r}')
TypeError: parameter 'user' is missing a type annotation in callback 'userping'
«аннотация типа» похожа на reason
; reason: str
. С помощью user = discord.Member
вы присваиваете user
объекту discord.Member
. Проще говоря, замените =
на :
.
# Code shortened for readability of error correction
@tree.command(guild=discord.Object(id=guild_id), name='userping', description='DM the user to come back to the ticket')
async def userping(interaction: discord.Interaction, reason: str, user: discord.Member):
...