discord-interactions.py

Upgrading to 0.3

What changes between 0.2 and 0.3, and what to adapt.

Code written for 0.2 runs on 0.3: every public import still exists. Four points need your attention.

1. Python 3.9 and discord.py 2.6#

pip install -U levraiberet-discord-interactions

2. Entity options arrive as objects#

In 0.2, User, Channel, Role, Mentionable and Attachment gave an ID. In 0.3, you receive the discord.py object directly.

# 0.2async def profile(ctx, member):    member = ctx.bot.get_user(int(member)) or await ctx.bot.fetch_user(int(member))  # 0.3async def profile(ctx, member):    await ctx.respond(member.display_name)

3. Default components are lighter#

Fields at their default value are no longer sent ("disabled": False, "required": True). Discord applies the same values; only code inspecting the generated dicts can notice.

4. Error handlers can hand over#

An @slash.on_error returning False lets the default handling respond. Any other return value, None included, keeps the 0.2 behavior.

Fixed without any change#

  • Autocompletes declared through String(..., autocomplete=...) are called.
  • DynamicCooldown works, and two simultaneous calls no longer bypass a cooldown.
  • Option, cooldown and permission decorators work on group subcommands.
  • content with components V2 is converted instead of being rejected by Discord.
  • owner_only() without a list reads the application's owners.

Deprecated#

PseudoContainerBuilder and the pseudo* functions imitate containers with embeds. Replace them with container(): they will be removed in 0.4.

Type a name: create_button, ModalBuilder, cooldown.