python - 是否可以在 dms 中使用斜杠命令来处理 discord py?

标签 python discord discord.py

enter image description here我不知道怎么做,但我很久以前就已经开始工作了,但我不再有代码了,而且我什至不使用它是斜杠命令还是常规命令。

如您所见,这是我在我的 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):

关于python - 是否可以在 dms 中使用斜杠命令来处理 discord py?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71806440/

相关文章:

python - 从 html %20 中转义

python - main 函数和/或 __name__ == "__main__"在 Python 中检查有什么意义?

python - 根据 channel 将输入图像张量切片或分割为变量

python - Django - 按方法排序查询集

javascript - 我的不和谐机器人上不断收到此错误 : 'HTTPError [AbortError]: The user aborted a request.'

Python discord bot - 从未等待过协程

javascript - 如何获取当前机器人状态?

python - 添加对消息的 react 。 Discord.py 重写

python - 没有名为 'discord.ext' 的模块; 'discord' 不是一个包

python - discord.py 邀请 - approximate_presence_count API 逐渐变慢