pythondiscorddiscord.pypycord

Does Py-cord support Discord's new User Install Commands feature?


I recently learned that Discord has updated with a feature called "User Install" that allows users to install bots to their personal accounts, not just servers. As I understand it, this enables users to use certain bot commands in servers where the bot isn't officially present.

I'm developing a Discord bot using py-cord and want to implement this new feature, but I can't find any information about it in the documentation.

My questions are:

  1. Does py-cord already support Discord's User Install Commands feature?
  2. If supported, how can I define and implement a command in py-cord that can be installed by users and used in any server?
  3. Are there any relevant decorators or special configurations to mark these types of commands?

My current code structure:

import discord
from discord.ext import commands

bot = commands.Bot()

# Regular slash command
@bot.slash_command(name="hello", description="Say hello")
async def hello(ctx):
    await ctx.respond(f"Hello, {ctx.author.name}!")

# I want to know how to modify this to be a user-installable command
# @bot.???_command(name="usercommand")
# async def user_command(ctx):
#     await ctx.respond("This is a user-installed command")

bot.run("TOKEN")

Thanks for any guidance or suggestions!


Solution

  • As of Pycord v2.6, this is supported.

    if you want your command to be available in both guilds and to users who have installed your bot, you can specify both guild_install and user_install in an integration types parameter inside a @bot.slash_command() decorator:

    @bot.slash_command(
        name="hello",
        description="say hello",
        integration_types={
            discord.IntegrationType.guild_install,
            discord.IntegrationType.user_install,
        },
    )
    async def hello(ctx: discord.ApplicationContext):
        await ctx.respond("hello!")