是否可以在 dms 中为 discord py 使用斜杠命令?

Is it possible to use slash commands in dms for discord py?

我不知道是怎么做到的,但我很久以前就开始使用它了,但是我没有代码了,如果它是斜线命令或常规命令,我什至不会使用它。

如您所见,这是我在我的 dms 中使用机器人。现在我有一个新的机器人,我正在尝试通过添加我个人帐户的公会 ID 来做到这一点,但它给了我这个错误

discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

我的斜杠命令是这样的:

from discord.ext import commands
from discord_slash import SlashCommand, SlashContext

bot = commands.Bot(command_prefix='$', intents=Intents.all())
slash = SlashCommand(bot, sync_commands=True)


@slash.slash(name="test", guild_ids=[guild_id_of_server])
async def test(ctx: SlashContext):
    ...

这在我的服务器中完美运行,我只是想让它在我的 dms 中运行。是否应该更改机器人的权限?

您添加了 guild_ids=[guild_id_of_server],因此它将仅在服务器

上工作
@slash.slash(name="test", guild_ids=[guild_id_of_server])
async def test(ctx: SlashContext):

只需将其删除即可!

@slash.slash(name="test")
async def test(ctx: SlashContext):