【发布时间】:2022-01-11 02:48:20
【问题描述】:
我正在使用 discord-py-slash-command 库并设置了我的命令。但是,当我在聊天中键入命令时,每次都会交互失败。我已经为我的机器人提供了正确的范围,并多次将其重新邀请到服务器。有人可以看看我的代码并告诉我发生了什么吗?我已经按照几个教程没有运气。
TOKEN = open("./token.txt", "r").readline()
bot = commands.Bot(command_prefix='-', intents=discord.Intents.all())
slash = SlashCommand(bot, sync_commands=True)
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to the Discord!')
@slash.slash(name="test", description='Test slash command activated', guild_ids=
[928451150515150890])
async def test(ctx: SlashContext):
embed = discord.Embed(title="Embed Test")
await ctx.send(embed=embed)
【问题讨论】:
-
您的代码非常适合我,您是否执行了以下操作? 1. 导入所有需要的模块 2. 使用
bot.run(TOKEN)启动你的机器人 3. 公会 ID 是正确的。 -
这段代码没有理由不工作。您是否以 application.commands 权限邀请您的机器人(来自 Discord 开发者页面的 OAuth url 生成器)?您的系统是否因任何原因而过载或网络连接太慢,如果机器人在 3 秒内没有响应,则表示交互失败,但您可以使用
ctx.defer方法来增加该时间 -
我确定我导入了所有内容。是的,我多次设置了 OAuth 生成器(每次都重新邀请我的机器人)。网络连接应该不是问题。不幸的是,ctx.defer() 也不能解决我的问题
标签: python discord discord.py