我最近了解到,Discord 更新了一项名为“用户安装”的功能,允许用户将机器人安装到个人账户,而不仅仅是服务器。据我了解,这项功能允许用户在机器人尚未正式上线的服务器中使用某些机器人命令。
我正在使用 py-cord 开发 Discord 机器人并想实现这个新功能,但我在文档中找不到有关它的任何信息。
我的问题是:
- py-cord 是否已经支持 Discord 的用户安装命令功能?
- 如果支持,我如何在 py-cord 中定义和实现一个可由用户安装并在任何服务器中使用的命令?
- 是否有相关的装饰器或特殊配置来标记这些类型的命令?
我当前的代码结构:
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")
感谢您的任何指导或建议!
从 Pycord v2.6 开始,此功能已得到支持。
如果您希望您的命令在公会和安装了您的机器人的用户中都可用,您可以在 @bot.slash_command() 装饰器内的集成类型参数中同时指定 guild_install 和 user_install: