Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: attribute error in command serialization #2243

Conversation

Mihitoko
Copy link
Contributor

@Mihitoko Mihitoko commented Oct 13, 2023

Summary

When Serializing commands which have a Annotated annotation it comes to a AttributeError because the type information is not wrapped in SlashCommand type.

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@Mihitoko
Copy link
Contributor Author

This PR will close #2223

@Mihitoko Mihitoko changed the title Fix attribute error in command serialization fix: attribute error in command serialization Oct 13, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
@Mihitoko
Copy link
Contributor Author

Mihitoko commented Nov 30, 2023

Sorry did not notice the comments,
Ill resolve the merge conflict later.
When im back from work

@Dorukyum Dorukyum added this to the v2.5 milestone Nov 30, 2023
@Dorukyum Dorukyum added bug Something isn't working priority: medium Medium Priority status: awaiting review Awaiting review from a maintainer labels Nov 30, 2023
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
@Dorukyum
Copy link
Member

I've solved the merge conflict and will approve after testing.

@Mihitoko
Copy link
Contributor Author

I've solved the merge conflict and will approve after testing.

Thank you

plun1331
plun1331 previously approved these changes Dec 1, 2023
Copy link
Member

@plun1331 plun1331 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with following:

import typing
import discord
from discord.ext import commands

bot = commands.Bot()

@bot.slash_command(options=[discord.Option(int, name="my-option", description="This is my option!")])
async def my_command1(ctx: discord.ApplicationContext, my_option: int):
    await ctx.respond("Hey, %d is my option!" % my_option)

@bot.slash_command()
async def my_command2(ctx: discord.ApplicationContext, my_option: discord.Option(int, name="my-option", description="This is my option!")):
    await ctx.respond("Hey, %d is my option!" % my_option)

@bot.slash_command()
async def my_command3(ctx: discord.ApplicationContext, my_option: typing.Annotated[int, discord.Option(int, name="my-option", description="This is my option!")]):
    await ctx.respond("Hey, %d is my option!" % my_option)

print(my_command1.to_dict())
print(my_command2.to_dict())
print(my_command3.to_dict())

@plun1331 plun1331 merged commit 5849d64 into Pycord-Development:master Dec 1, 2023
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: medium Medium Priority status: awaiting review Awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: type object '<type>' has no attribute 'value' when using typing.Annotated
4 participants